<?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: How to get calculation time from date command in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858473#M867571</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I would prefer the perl solution; it looks very elegant.&lt;BR /&gt;&lt;BR /&gt;If you insist on using shell command, you can try the attached script, return_seconds.sh. It does nothing more than count seconds back to e.g. 1970, and it cannot take your format as input.&lt;BR /&gt;&lt;BR /&gt;In order to turn a number of seconds into a date (not in your requested format either) I suggest adb: in the example below I change my TZ before converting, else 2 hours are added. Example:&lt;BR /&gt;&lt;BR /&gt;jk# CURRENT_DATE=$( ./return_seconds.sh 1970 2004 08 01 00 00 20 )&lt;BR /&gt;jk# echo $CURRENT_DATE&lt;BR /&gt;1091318420&lt;BR /&gt;jk# AFTER_DATE=$(( $CURRENT_DATE + 50 ))&lt;BR /&gt;jk# echo $AFTER_DATE&lt;BR /&gt;1091318470&lt;BR /&gt;jk# BEFORE_DATE=$(( $CURRENT_DATE - 50 ))&lt;BR /&gt;jk# echo $BEFORE_DATE&lt;BR /&gt;1091318370&lt;BR /&gt;jk# echo $TZ&lt;BR /&gt;MET-1METDST&lt;BR /&gt;jk# TZ=METMETDST&lt;BR /&gt;jk# echo 0d${AFTER_DATE}=Y|adb&lt;BR /&gt;                2004 Aug  1 00:01:10&lt;BR /&gt;jk# echo 0d${BEFORE_DATE}=Y|adb&lt;BR /&gt;                2004 Jul 31 23:59:30&lt;BR /&gt;jk#&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;No guarantee that the script works! &lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
    <pubDate>Mon, 30 Aug 2004 08:02:04 GMT</pubDate>
    <dc:creator>john korterman</dc:creator>
    <dc:date>2004-08-30T08:02:04Z</dc:date>
    <item>
      <title>How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858464#M867562</link>
      <description>How to get calculation time from date command&lt;BR /&gt;&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;How to get calculation time(seconds) from date&lt;BR /&gt;command ? &lt;BR /&gt;&lt;BR /&gt;For example&lt;BR /&gt;current_date=08/01/2004 00:00:20&lt;BR /&gt;&lt;BR /&gt;after_date=${current_date} + 50&lt;BR /&gt;result -&amp;gt; 08/01/2004 00:01:10&lt;BR /&gt;&lt;BR /&gt;before_date=${current_date} - 50&lt;BR /&gt;result -&amp;gt; 07/31/2004 23:59:30&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Fri, 27 Aug 2004 04:07:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858464#M867562</guid>
      <dc:creator>양홍석_1</dc:creator>
      <dc:date>2004-08-27T04:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858465#M867563</link>
      <description>&lt;BR /&gt;Please use the Forum SEARCH function to find dozens of prior discussions and answers to this and similar question.&lt;BR /&gt;&lt;BR /&gt;You'll probably end up using: caljd.sh&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Aug 2004 08:18:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858465#M867563</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-27T08:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858466#M867564</link>
      <description>hi hein,&lt;BR /&gt;&lt;BR /&gt;caljd.sh is possible calculation time in seconds?</description>
      <pubDate>Fri, 27 Aug 2004 19:17:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858466#M867564</guid>
      <dc:creator>양홍석_1</dc:creator>
      <dc:date>2004-08-27T19:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858467#M867565</link>
      <description>Argh, now I feel bad... caljd stands for calendar / julian / date and is only concerned with dates, not times.&lt;BR /&gt;&lt;BR /&gt;Here is a little bit of perl that will do the job. Convert to subroutine if needed:&lt;BR /&gt;&lt;BR /&gt;$cat time.pl&lt;BR /&gt;use Time::Local;&lt;BR /&gt;if (/(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)\s*([- +])\s*(\d+)/) {&lt;BR /&gt;  $time = timelocal($6,$5,$4,$2,$1-1,$3);&lt;BR /&gt;  $time += ($7 eq "-")? -$8 : $8;&lt;BR /&gt;  ($sec,$min,$hour,$mday,$mon,$year) = localtime $time;&lt;BR /&gt;  printf ("%02d/%02d/%4d %02d:%02d:%02d\n",&lt;BR /&gt;1+$mon,$mday,1900+$year,$hour,$min,$sec);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;This perl code matches an input string against "mm/dd/yyyy hh:mm:ss", followed by a plus, minus, or space, followed by a number.&lt;BR /&gt;Each component is remembered in $1 thru $8 using ()'s.&lt;BR /&gt;Then we use the perl module Time::Local function 'timelocal' to convert this to seconds since begin of time.&lt;BR /&gt;Next add or subtract the delta and convert back to components with standard 'localtime'.&lt;BR /&gt;Finally print result with format similar to input.&lt;BR /&gt;&lt;BR /&gt;Working example:&lt;BR /&gt;&lt;BR /&gt;$ echo "08/01/2004 00:00:20 -50" | perl -n time.pl&lt;BR /&gt;07/31/2004 23:59:30&lt;BR /&gt;$ echo "08/01/2004 00:00:20 +50" | perl -n time.pl&lt;BR /&gt;08/01/2004 00:01:10&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Aug 2004 23:57:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858467#M867565</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-27T23:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858468#M867566</link>
      <description>hi&lt;BR /&gt;&lt;BR /&gt;It is helpful many.&lt;BR /&gt;But I need the solution to use a date command.&lt;BR /&gt;I need to use at a Shell Script.</description>
      <pubDate>Sun, 29 Aug 2004 08:51:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858468#M867566</guid>
      <dc:creator>양홍석_1</dc:creator>
      <dc:date>2004-08-29T08:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858469#M867567</link>
      <description>&lt;BR /&gt;Yeah well... just put the whole thing in backticks and feed to date?! Or READ the result into a symbol and feed that into date.&lt;BR /&gt;&lt;BR /&gt;Or... just call 'date' in the perl script directly.&lt;BR /&gt;&lt;BR /&gt;Of course if you want to feed into date, then you do NOT want results like '07/31/2004 23:59:30' but you possibly would like a format: mmddhhmm[[cc]yy&lt;BR /&gt;So just change the file printf (or sprintf if you are going to do all within perl) to&lt;BR /&gt;&lt;BR /&gt;  printf ("%02d%02d%02d%02d%4d\n", 1+$mon,$mday,$hour,$min,1900+$year);&lt;BR /&gt;&lt;BR /&gt;However... what problem are you really trying to solve? Do you intend to adjust the clock? The please first check out 'man date' and look for he -a (adjust) option!&lt;BR /&gt;&lt;BR /&gt;Good luck,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 29 Aug 2004 13:46:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858469#M867567</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-29T13:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858470#M867568</link>
      <description>perl -e 'print(localtime(time()+@ARGV[1])."\n")' -- &lt;OFFSET in="" seconds=""&gt;&lt;BR /&gt;&lt;BR /&gt;So, your lines would become:&lt;BR /&gt;after_date=$(perl -e 'print(localtime(time()+@ARGV[1])."\n")' -- 50)&lt;BR /&gt;&lt;BR /&gt;etc.&lt;BR /&gt;&lt;BR /&gt;If you want to calculate from currant_date, you would need to convert it back to seconds-since-jan-1970... and replace the time() in the perl routine to that value.&lt;BR /&gt;&lt;BR /&gt;Using the date command will not work, I'm afraid. You could do what you want using awk instead of perl, but the result would be the same...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/OFFSET&gt;</description>
      <pubDate>Mon, 30 Aug 2004 01:45:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858470#M867568</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-08-30T01:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858471#M867569</link>
      <description>We can do this as,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;set -x&lt;BR /&gt;check="yes"&lt;BR /&gt;&lt;BR /&gt;while [[ "$check" = "yes" ]]&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;TIME=`date +'%X'`&lt;BR /&gt;echo "Current time: `date`"&lt;BR /&gt;&lt;BR /&gt;echo "Enter your value to increment / decrement time(seconds)"&lt;BR /&gt;echo "Example +10 or -10"&lt;BR /&gt;&lt;BR /&gt;read sec&lt;BR /&gt;&lt;BR /&gt;TOTAL=`echo $TIME | awk -F ":" '{ print ($1*3600)+($2*60)+$3 }'`&lt;BR /&gt;let NEWVAL=$TOTAL+$sec&lt;BR /&gt;&lt;BR /&gt;DATE=$(echo "`echo $(($NEWVAL/3600))`:`echo $(($(($NEWVAL%3600))/60))`:`echo $(($(($NEWVAL%3600))%60))`")&lt;BR /&gt;&lt;BR /&gt;echo "Current date+timing"&lt;BR /&gt;echo "`date +'%a %b %d'` `echo $DATE` `date +'%z %Y'`"&lt;BR /&gt;&lt;BR /&gt;echo "Do you want to continue (yes/no)"&lt;BR /&gt;read check&lt;BR /&gt;&lt;BR /&gt;sleep 1&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;#&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;It will give the way to do. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Aug 2004 03:05:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858471#M867569</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-08-30T03:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858472#M867570</link>
      <description>HI,&lt;BR /&gt;Not sure but just wanted to know whether "timex" command would help you out!!&lt;BR /&gt;Regards,</description>
      <pubDate>Mon, 30 Aug 2004 03:06:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858472#M867570</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-08-30T03:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858473#M867571</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I would prefer the perl solution; it looks very elegant.&lt;BR /&gt;&lt;BR /&gt;If you insist on using shell command, you can try the attached script, return_seconds.sh. It does nothing more than count seconds back to e.g. 1970, and it cannot take your format as input.&lt;BR /&gt;&lt;BR /&gt;In order to turn a number of seconds into a date (not in your requested format either) I suggest adb: in the example below I change my TZ before converting, else 2 hours are added. Example:&lt;BR /&gt;&lt;BR /&gt;jk# CURRENT_DATE=$( ./return_seconds.sh 1970 2004 08 01 00 00 20 )&lt;BR /&gt;jk# echo $CURRENT_DATE&lt;BR /&gt;1091318420&lt;BR /&gt;jk# AFTER_DATE=$(( $CURRENT_DATE + 50 ))&lt;BR /&gt;jk# echo $AFTER_DATE&lt;BR /&gt;1091318470&lt;BR /&gt;jk# BEFORE_DATE=$(( $CURRENT_DATE - 50 ))&lt;BR /&gt;jk# echo $BEFORE_DATE&lt;BR /&gt;1091318370&lt;BR /&gt;jk# echo $TZ&lt;BR /&gt;MET-1METDST&lt;BR /&gt;jk# TZ=METMETDST&lt;BR /&gt;jk# echo 0d${AFTER_DATE}=Y|adb&lt;BR /&gt;                2004 Aug  1 00:01:10&lt;BR /&gt;jk# echo 0d${BEFORE_DATE}=Y|adb&lt;BR /&gt;                2004 Jul 31 23:59:30&lt;BR /&gt;jk#&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;No guarantee that the script works! &lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Mon, 30 Aug 2004 08:02:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858473#M867571</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2004-08-30T08:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858474#M867572</link>
      <description>hope the file is attached now...</description>
      <pubDate>Mon, 30 Aug 2004 08:43:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858474#M867572</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2004-08-30T08:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858475#M867573</link>
      <description>&lt;BR /&gt;Along those lines, here is a shell script I did to get the time in seconds for the start of a given day (YYYY MM DD)&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i YEAR=1970 MONTH=0 DAYS=0 SECS=0 LEAP=0&lt;BR /&gt;while [ $YEAR -lt $1 ]&lt;BR /&gt;do&lt;BR /&gt;# script only valid from 1970 - 2032, so 100 and 400 year rule cancel&lt;BR /&gt;#  echo $YEAR $DAYS $SECS&lt;BR /&gt;  DAYS=$(( $DAYS + 365 + $LEAP ))&lt;BR /&gt;  YEAR=$(( $YEAR + 1 ))&lt;BR /&gt;  if [ $(($YEAR % 4 )) -eq 0 ];  then LEAP=1; else LEAP=0; fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;# script could pre-add days in month and select from list without loop&lt;BR /&gt;for DAYS_IN_MONTH in 31 28 31 30 31 30 31 31 30 31 30 31&lt;BR /&gt;do&lt;BR /&gt;  MONTH=$(( $MONTH + 1 ))&lt;BR /&gt;  if [ $MONTH -eq 3 ]; then DAYS=$(( $DAYS + $LEAP )); fi&lt;BR /&gt;  if [ $MONTH -ge $2 ]; then break; fi&lt;BR /&gt;  DAYS=$(( $DAYS + $DAYS_IN_MONTH ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;DAYS=$(( $DAYS + $3 - 1 ))&lt;BR /&gt;SECS=$(( $DAYS * 86400 ))&lt;BR /&gt;&lt;BR /&gt;echo $DAYS $SECS&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The same thing in perl, but with error handling:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;($year,$month,$day) = @ARGV;&lt;BR /&gt;die "Please provide year month day arguments" unless $day;&lt;BR /&gt;die "Year must be between 1970 and 2032" if (($year &amp;lt; 1970) || ($year &amp;gt; 2032));&lt;BR /&gt;use Time::Local;&lt;BR /&gt;$time = timegm(0,0,0,$day,$month-1,$year);&lt;BR /&gt;$days = $time / 86400;&lt;BR /&gt;print "$days $time\n";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Back to the real problem....&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Aug 2004 14:21:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858475#M867573</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-30T14:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get calculation time from date command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858476#M867574</link>
      <description>thanks for helpful.</description>
      <pubDate>Mon, 30 Aug 2004 23:38:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-calculation-time-from-date-command/m-p/4858476#M867574</guid>
      <dc:creator>양홍석_1</dc:creator>
      <dc:date>2004-08-30T23:38:00Z</dc:date>
    </item>
  </channel>
</rss>

