<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: convert human readable to epoch secs in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564801#M679117</link>
    <description>In your example in the second response, you're also going to get incorrect results by using timegm() to go to epoch, and then localtime() to convert back for your test.&lt;BR /&gt;&lt;BR /&gt;You need to use timegm() and gmtime() together, or timelocal() and localtime() together, in order to get the same thing out as what you put in.&lt;BR /&gt;&lt;BR /&gt;The timelocal() and timegm() functions use the same array format as localtime() and gmtime(), as you discovered, with month = 0..11</description>
    <pubDate>Fri, 15 Jan 2010 18:42:10 GMT</pubDate>
    <dc:creator>mvpel</dc:creator>
    <dc:date>2010-01-15T18:42:10Z</dc:date>
    <item>
      <title>convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564795#M679111</link>
      <description>Hello Folks,&lt;BR /&gt;There are numerous postings on converting human date to epoch, but I am looking for a perl or shell one-liner. &lt;BR /&gt;I am doing some automation and bumped into a date validation and time elapsed since a particular date, the output that I get from a query for particular timestamp column is in this format:&lt;BR /&gt;14-JAN-2010 17:21:38&lt;BR /&gt;&lt;BR /&gt;I need to pass this value and use the built-in perl localtime/date functions to output this format to epoch secs.&lt;BR /&gt;&lt;BR /&gt;From going through these forums, I can convert current date to epoch and the output of that to the format that I want, but how do I convert the same format back to epoch?&lt;BR /&gt;&lt;BR /&gt;##Convert current time to epoch secs&lt;BR /&gt;# perl -e "print time"&lt;BR /&gt;&lt;BR /&gt;## Convert epoch to a timestamp format that I want&lt;BR /&gt;# perl -MPOSIX -e 'print strftime "%Y-%m-%d %H:%M:%S\n",localtime(1263520672)'&lt;BR /&gt;&lt;BR /&gt;## Convert the same timestamp (%Y-%m-%d %H:%M:%S) format to epoch?&lt;BR /&gt;???&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jan 2010 02:02:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564795#M679111</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2010-01-15T02:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564796#M679112</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;check this site, there is a pelr script :&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unixtutorial.org/2009/02/converting-date-and-time-to-unix-epoch-in-perl/" target="_blank"&gt;http://www.unixtutorial.org/2009/02/converting-date-and-time-to-unix-epoch-in-perl/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;mikap</description>
      <pubDate>Fri, 15 Jan 2010 04:42:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564796#M679112</guid>
      <dc:creator>Michal Kapalka (mikap)</dc:creator>
      <dc:date>2010-01-15T04:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564797#M679113</link>
      <description>Thanks.&lt;BR /&gt;That helps a little bit, but I am still playing around with it, doesn't give me the correct info yet ..&lt;BR /&gt;&lt;BR /&gt;Timestamp is 14-JAN-2010 20:33:38&lt;BR /&gt;#perl -MTime::Local -le '$epoch_secs = timegm(38,33,20,14,01,110); print "$epoch_secs";'&lt;BR /&gt;1266179618&lt;BR /&gt;&lt;BR /&gt;#perl -e "print scalar(localtime(1266179618))"&lt;BR /&gt;Sun Feb 14 12:33:38 2010&lt;BR /&gt;&lt;BR /&gt;Returns incorrect info?</description>
      <pubDate>Fri, 15 Jan 2010 05:04:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564797#M679113</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2010-01-15T05:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564798#M679114</link>
      <description>hmm... interesting, further reading on the web says timelocal month param starts from 00 thru 11 (Jan thru Dec) ... that answers why it was returning Feb ...&lt;BR /&gt;&lt;BR /&gt;Other solutions are welcome too ...&lt;BR /&gt;&lt;BR /&gt;I'll leave this thread Open ...&lt;BR /&gt;&lt;BR /&gt;Thanks,</description>
      <pubDate>Fri, 15 Jan 2010 05:22:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564798#M679114</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2010-01-15T05:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564799#M679115</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Here's a small script that lets you pass a date and time argument.  It converts this to epoch seconds for output.  Leading zeros in the input fields are unnecessary, and the month name can be either lower or uppercase letters or mixed.&lt;BR /&gt;&lt;BR /&gt;# cat ./mytime&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use Time::Local;&lt;BR /&gt;my %months =&lt;BR /&gt;    ( 'JAN'=&amp;gt;1, 'FEB'=&amp;gt;2, 'MAR'=&amp;gt;3, 'APR'=&amp;gt;4,  'MAY'=&amp;gt;5,  'JUN'=&amp;gt;6,&lt;BR /&gt;      'JUL'=&amp;gt;7, 'AUG'=&amp;gt;8, 'SEP'=&amp;gt;9, 'OCT'=&amp;gt;10, 'NOV'=&amp;gt;11, 'DEC'=&amp;gt;12&lt;BR /&gt;    );&lt;BR /&gt;my $date = shift or die "DD-MMM-YYYY expected\n";&lt;BR /&gt;my $time = shift or die "HH:MM:SS expected\n";&lt;BR /&gt;my ( $mday, $mon, $year ) = split /-/, $date;&lt;BR /&gt;my ( $hours, $min, $sec ) = split /:/, $time;&lt;BR /&gt;print timelocal($sec,$min,$hours,$mday,$months{uc($mon)}-1,$year-1900),"\n";&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# ./mytime 14-JAN-2010 17:21:38&lt;BR /&gt;1263507698&lt;BR /&gt;# perl -le 'print scalar localtime(1263507698)'&lt;BR /&gt;Thu Jan 14 17:21:38 2010&lt;BR /&gt;&lt;BR /&gt;# ./mytime 8-Apr-2010 8:17:23&lt;BR /&gt;1270729043&lt;BR /&gt;# perl -wle 'print scalar localtime(1270729043)'&lt;BR /&gt;Thu Apr  8 08:17:23 2010&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jan 2010 12:59:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564799#M679115</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-15T12:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564800#M679116</link>
      <description>Hi Shabu,&lt;BR /&gt;&lt;BR /&gt;I assume that your first perl statement sums a number of values and "01" in (38,33,20,14,01,110) will include the full first month - which it should not as long as we are still in January.&lt;BR /&gt;You need to convert JAN to 00, FEB to  01, etc., before feeding it to your first perl command,e.g.:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;TIMESTAMP="14-JAN-2010 17:21:38"&lt;BR /&gt;&lt;BR /&gt;export DA=$(echo "$TIMESTAMP"| awk -F"(-|:|\ )" '{print $1}')&lt;BR /&gt;export MO=$(echo "$TIMESTAMP"| awk -F"(-|:|\ )" '{print $2}')&lt;BR /&gt;export YE=$(echo "$TIMESTAMP"| awk -F"(-|:|\ )" '{print $3}')&lt;BR /&gt;export HO=$(echo "$TIMESTAMP"| awk -F"(-|:|\ )" '{print $4}')&lt;BR /&gt;export MI=$(echo "$TIMESTAMP"| awk -F"(-|:|\ )" '{print $5}')&lt;BR /&gt;export SE=$(echo "$TIMESTAMP"| awk -F"(-|:|\ )" '{print $6}')&lt;BR /&gt;&lt;BR /&gt;case $MO in&lt;BR /&gt;JAN) MO=00;;&lt;BR /&gt;FEB) MO=01;;&lt;BR /&gt;MAR) MO=02;;&lt;BR /&gt;# fill in your month representation....&lt;BR /&gt;esac;&lt;BR /&gt;&lt;BR /&gt;SECONDS=$(perl -MTime::Local -le '$epoch_secs = timegm($ENV{'SE'},$ENV{'MI'},$ENV{'HO'},$ENV{'DA'},$ENV{'MO'},$ENV{'YE'}); print "$epoch_secs";')&lt;BR /&gt;&lt;BR /&gt;echo $SECONDS&lt;BR /&gt;&lt;BR /&gt;echo "0d${SECONDS}=y"| adb&lt;BR /&gt;# end of example&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jan 2010 13:26:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564800#M679116</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2010-01-15T13:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564801#M679117</link>
      <description>In your example in the second response, you're also going to get incorrect results by using timegm() to go to epoch, and then localtime() to convert back for your test.&lt;BR /&gt;&lt;BR /&gt;You need to use timegm() and gmtime() together, or timelocal() and localtime() together, in order to get the same thing out as what you put in.&lt;BR /&gt;&lt;BR /&gt;The timelocal() and timegm() functions use the same array format as localtime() and gmtime(), as you discovered, with month = 0..11</description>
      <pubDate>Fri, 15 Jan 2010 18:42:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564801#M679117</guid>
      <dc:creator>mvpel</dc:creator>
      <dc:date>2010-01-15T18:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564802#M679118</link>
      <description>Thanks for responding folks. I got this done last night after the pointer from mikap.&lt;BR /&gt;&lt;BR /&gt;Here is how I got this done ... part of the script ...&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;     JOB_ID="$(echo ${LINE} | cut -d '|' -f1)"&lt;BR /&gt;     START_TIME="$(echo ${LINE} | cut -d '|' -f2)"&lt;BR /&gt;     STATUS="$(echo ${LINE} | awk '{print $NF}')"&lt;BR /&gt;&lt;BR /&gt;     export SS="$(echo ${START_TIME} | cut -d_ -f1)"&lt;BR /&gt;     export MM="$(echo ${START_TIME} | cut -d_ -f2)"&lt;BR /&gt;     export HH="$(echo ${START_TIME} | cut -d_ -f3)"&lt;BR /&gt;     export DD="$(echo ${START_TIME} | cut -d_ -f4)"&lt;BR /&gt;     export MM="$(echo ${START_TIME} | cut -d_ -f5)"&lt;BR /&gt;     export YY="$(echo ${START_TIME} | cut -d_ -f6)"&lt;BR /&gt;&lt;BR /&gt;     START_TIME_IN_EPOCH_SECS="$(perl -MTime::Local -le '$epoch_secs = timelocal('$SS','$MM','$HH','$DD','$MM','$YY'); print "$epoch_secs";')"&lt;BR /&gt;     CURR_TIME_IN_EPOCH_SECS="$(perl -le "print time")"&lt;BR /&gt;     ELAPSED_TIME_IN_EPOCH_SECS="$(expr ${CURR_TIME_IN_EPOCH_SECS} - ${START_TIME_IN_EPOCH_SECS})"&lt;BR /&gt;     ELPASED_TIME_IN_MINS="$(echo ${ELAPSED_TIME_IN_EPOCH_SECS}/60 | bc)"&lt;BR /&gt;&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;Kind of the same way that John suggested.&lt;BR /&gt;&lt;BR /&gt;Thanks,</description>
      <pubDate>Fri, 15 Jan 2010 19:08:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564802#M679118</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2010-01-15T19:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564803#M679119</link>
      <description>Not sure where my new 'reopen' thread went ...&lt;BR /&gt;&lt;BR /&gt;This is what I was asking...&lt;BR /&gt;&lt;BR /&gt;Reopening ...&lt;BR /&gt;&lt;BR /&gt;I am running to a weird condition ...&lt;BR /&gt;the Output that I am parsing is this:&lt;BR /&gt;16295|38_08_12_19_JAN_2010|||STARTED&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# perl -MTime::Local -le '$epoch_secs = timelocal('${SS}','${MM}','${HH}','${DD}','${MON}','${YY}'); print "$epoch_secs";'&lt;BR /&gt;Illegal octal digit '8' at -e line 1, at end of line&lt;BR /&gt;Execution of -e aborted due to compilation errors.&lt;BR /&gt;&lt;BR /&gt;12:08 pm is the time that this job started.&lt;BR /&gt;Anyone know why its complaining about '08' Minutes - ${MM} variable?&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jan 2010 21:19:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564803#M679119</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2010-01-19T21:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564804#M679120</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Anyone know why its complaining about '08' Minutes - ${MM} variable?&lt;BR /&gt;&lt;BR /&gt;Yes, this is your *shell* interpreting the leading zero as signifying an *octal* value.  If would need to drop the leading zero.&lt;BR /&gt;&lt;BR /&gt;Of course if you use my slightly larger script, you can pass leading zeros or not :-)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jan 2010 21:31:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564804#M679120</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-19T21:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564805#M679121</link>
      <description>Thanks JRF.&lt;BR /&gt;It works from 01 thru 07, when I remove the '0' for 08 and 09 it works, may be I can sed out the 0 when it is 08 and 09 ...&lt;BR /&gt;&lt;BR /&gt;Any other conditions I need to be aware of?</description>
      <pubDate>Tue, 19 Jan 2010 21:48:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564805#M679121</guid>
      <dc:creator>Shabu Khan-2</dc:creator>
      <dc:date>2010-01-19T21:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564806#M679122</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; may be I can sed out the 0 when it is 08 and 09 ...Any other conditions I need to be aware of?&lt;BR /&gt;&lt;BR /&gt;Ridding the shell variables of leading zeros will eliminate your problem.  The Perl script I offered eliminates the shell snipping, filtering and multiple variables, though.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 19 Jan 2010 22:14:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564806#M679122</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-19T22:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: convert human readable to epoch secs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564807#M679123</link>
      <description>&amp;gt;maybe I can sed out the 0 when it is 08 and 09&lt;BR /&gt;&lt;BR /&gt;You can also use typeset: typeset -LZ var="09"</description>
      <pubDate>Wed, 20 Jan 2010 22:18:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/convert-human-readable-to-epoch-secs/m-p/4564807#M679123</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-20T22:18:20Z</dc:date>
    </item>
  </channel>
</rss>

