AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
#Operatingsystems
#Servers
 View Only
  • 1.  convert a specific date to unix timestamp

    Posted 03/19/12 02:45 AM

    Originally posted by: tucero


    Hello,

    I have an AIX5.3 machine and i want to make a script where i will input a specific time and convert it to a unix timestamp.
    i have search the web and also asked this question to other aix forums as well but i cannot get a solution for this.
    Note that i cannot use the command {date -d}

    Are there any suggestions?

    Thank you
    #AIX-Forum


  • 2.  Re: convert a specific date to unix timestamp

    Posted 03/19/12 10:39 AM

    Originally posted by: j.gann


    check out the mktime function in perl's POSIX core module
    #AIX-Forum


  • 3.  Re: convert a specific date to unix timestamp

    Posted 03/20/12 12:24 AM

    Originally posted by: SystemAdmin


    If you have perl installed, then create mkepoch in vi and copy in the following code:
    
    #!/usr/bin/perl # Usage: mkepoch yyyy mm dd HH MM SS use Time::Local; ($yyyy, $mm,  $dd, $HHMMSS)=@ARGV; ($HH, $MM, $SS)=split(
    ":",$HHMMSS); $tm=timelocal($SS, $MM, $HH, $dd, $mm - 1, $yyyy); print 
    "$tm\n";
    


    Make executable, and test.
    #AIX-Forum


  • 4.  Re: convert a specific date to unix timestamp

    Posted 03/20/12 12:42 AM

    Originally posted by: SystemAdmin


    Sorry, old age is catching up. Try this one instead.
    
    #!/usr/bin/perl # Usage: mkepoch yyyy mm dd HH MM SS use Time::Local; ($yyyy, $mm,  $dd, $HH, $MM, $SS)=@ARGV; $tm=timelocal($SS, $MM, $HH, $dd, $mm - 1, $yyyy); print 
    "$tm\n";
    

    #AIX-Forum


  • 5.  Re: convert a specific date to unix timestamp

    Posted 03/20/12 02:39 AM

    Originally posted by: tucero


    i tried the script written by spook but i get the following error:
    "Month '-1' out of range 0..11 at ./test line 5"
    #AIX-Forum


  • 6.  Re: convert a specific date to unix timestamp

    Posted 03/20/12 04:16 AM

    Originally posted by: wdephoff


    You have to read the Usage:

    #!/usr/bin/perl
    1. Usage: mkepoch yyyy mm dd HH MM SS
    use Time::Local;
    ($yyyy, $mm, $dd, $HH, $MM, $SS)=@ARGV;
    $tm=timelocal($SS, $MM, $HH, $dd, $mm - 1, $yyyy);
    print "$tm\n";

    And run it (here under Windows):

    c:\perl>perl mkepoch.pl 2012 03 20 09 13 00
    1332231180
    #AIX-Forum


  • 7.  Re: convert a specific date to unix timestamp

    Posted 03/20/12 06:52 AM

    Originally posted by: tucero


    Ok thank you very much!
    It worked perfect!
    #AIX-Forum