<?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: Calculate time difference in Unix shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861734#M820781</link>
    <description>Hi Melvin,&lt;BR /&gt;there is probably no easy way of doing that. I was once requested to do something similar and I ended up making the attached script. It is slow but can return the number of seconds elapsed since midnight, Jan 1 of a specified year, e.g. 1970 and a certain specified date.&lt;BR /&gt;Example:&lt;BR /&gt;&lt;BR /&gt;# ./return_seconds.sh 1970 2002 11 14 9 31 00&lt;BR /&gt;# 1037266260&lt;BR /&gt;&lt;BR /&gt;The attached script can - if executed without parameters -  also calculate the number of seconds elapsed since midnight Jan 1 1970 and current system time, e.g.:&lt;BR /&gt;# ./return_seconds.sh&lt;BR /&gt;1039595802&lt;BR /&gt;&lt;BR /&gt;Difference:&lt;BR /&gt;# echo 1039596799 - 1037266260 | bc&lt;BR /&gt;2330539&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However, if you do not expect the time difference to be bigger than a few days you can speed up things by only counting back to midnight of  e.g. the current year, e.g.:&lt;BR /&gt;# date&lt;BR /&gt;Ons. 11 Dec. 2002  08:45&lt;BR /&gt;&lt;BR /&gt;# ./return_seconds.sh 2002 2002 Dec 11 8 45 00&lt;BR /&gt;29753100&lt;BR /&gt;&lt;BR /&gt;./return_seconds.sh 2002 2002 11 14 9 31 00&lt;BR /&gt;27423060&lt;BR /&gt;&lt;BR /&gt;# echo 29753100 - 27423060 | bc&lt;BR /&gt;2330040&lt;BR /&gt; &lt;BR /&gt;As time is passing the two results are not identical...&lt;BR /&gt;Hope it is of some use, but if you wait long enough I am sure someone will come up with a perl one-liner!&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 11 Dec 2002 08:13:49 GMT</pubDate>
    <dc:creator>john korterman</dc:creator>
    <dc:date>2002-12-11T08:13:49Z</dc:date>
    <item>
      <title>Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861732#M820779</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I have a question on shell scripting. I have a scenario whereby an application has captured the start timestamp on a file in the format of &lt;BR /&gt;2002-11-14 09:31 when the application services started up.&lt;BR /&gt;&lt;BR /&gt;I am required to produce a script to calculate the time difference between the current system date with the timestamp captured on the file I have mentioned above. The checking is scheduled to run every 4 hours.&lt;BR /&gt;&lt;BR /&gt;I am wondering is there a way that I can do a conversion of the time captured on file into a value where I can do the mathematical expression such as subtraction.&lt;BR /&gt;&lt;BR /&gt;My objective is to subtract the current system date with the timestamp that was captured on the file.&lt;BR /&gt;&lt;BR /&gt;time_difference=curr_date - prev_timestamp&lt;BR /&gt;&lt;BR /&gt;How can this be done if I were to use the shell script to calculate the time difference. Appreciate if you could give me some advice on how to get this done. Thank you.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Melvin</description>
      <pubDate>Wed, 11 Dec 2002 02:08:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861732#M820779</guid>
      <dc:creator>Melvin Thong</dc:creator>
      <dc:date>2002-12-11T02:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861733#M820780</link>
      <description>I suggest you read this link for Clay's script (caljd.sh):&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xea948cc5e03fd6118fff0090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xea948cc5e03fd6118fff0090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Plus have a look here for a lot of scripts:&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x026250011d20d6118ff40090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x026250011d20d6118ff40090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Wed, 11 Dec 2002 02:19:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861733#M820780</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-12-11T02:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861734#M820781</link>
      <description>Hi Melvin,&lt;BR /&gt;there is probably no easy way of doing that. I was once requested to do something similar and I ended up making the attached script. It is slow but can return the number of seconds elapsed since midnight, Jan 1 of a specified year, e.g. 1970 and a certain specified date.&lt;BR /&gt;Example:&lt;BR /&gt;&lt;BR /&gt;# ./return_seconds.sh 1970 2002 11 14 9 31 00&lt;BR /&gt;# 1037266260&lt;BR /&gt;&lt;BR /&gt;The attached script can - if executed without parameters -  also calculate the number of seconds elapsed since midnight Jan 1 1970 and current system time, e.g.:&lt;BR /&gt;# ./return_seconds.sh&lt;BR /&gt;1039595802&lt;BR /&gt;&lt;BR /&gt;Difference:&lt;BR /&gt;# echo 1039596799 - 1037266260 | bc&lt;BR /&gt;2330539&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However, if you do not expect the time difference to be bigger than a few days you can speed up things by only counting back to midnight of  e.g. the current year, e.g.:&lt;BR /&gt;# date&lt;BR /&gt;Ons. 11 Dec. 2002  08:45&lt;BR /&gt;&lt;BR /&gt;# ./return_seconds.sh 2002 2002 Dec 11 8 45 00&lt;BR /&gt;29753100&lt;BR /&gt;&lt;BR /&gt;./return_seconds.sh 2002 2002 11 14 9 31 00&lt;BR /&gt;27423060&lt;BR /&gt;&lt;BR /&gt;# echo 29753100 - 27423060 | bc&lt;BR /&gt;2330040&lt;BR /&gt; &lt;BR /&gt;As time is passing the two results are not identical...&lt;BR /&gt;Hope it is of some use, but if you wait long enough I am sure someone will come up with a perl one-liner!&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Dec 2002 08:13:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861734#M820781</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2002-12-11T08:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861735#M820782</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;the same question:&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x31d5cdec06f1d61190050090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x31d5cdec06f1d61190050090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Wed, 11 Dec 2002 08:28:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861735#M820782</guid>
      <dc:creator>Christian Gebhardt</dc:creator>
      <dc:date>2002-12-11T08:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861736#M820783</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;Simple C program (compile with make) then use within a shell script like :&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;# get date in VAR for example :&lt;BR /&gt;VAR=$(cat file | line | cut -c1-2)&lt;BR /&gt;# use my prog (each field from date is an arg)&lt;BR /&gt;myprog $(echo $VAR | tr ':-' '  ')&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Wed, 11 Dec 2002 09:16:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861736#M820783</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-12-11T09:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861737#M820784</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am not aware of a shell command that would make this easy; but if you look at&lt;BR /&gt;&lt;A href="http://docs.hp.com/cgi-bin/onlinedocs.py?mpn=B2355-90683&amp;amp;service=hpux&amp;amp;path=../B2355-90683/00/00/89&amp;amp;title=HP-UX%20Reference%20Volume%204%3A%20Section%203" target="_blank"&gt;http://docs.hp.com/cgi-bin/onlinedocs.py?mpn=B2355-90683&amp;amp;service=hpux&amp;amp;path=../B2355-90683/00/00/89&amp;amp;title=HP-UX%20Reference%20Volume%204%3A%20Section%203&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;you'll find how to use difftime() to get the time difference between two dates...&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;FiX</description>
      <pubDate>Wed, 11 Dec 2002 10:08:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861737#M820784</guid>
      <dc:creator>F. X. de Montgolfier</dc:creator>
      <dc:date>2002-12-11T10:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate time difference in Unix shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861738#M820785</link>
      <description>Hi Melvin,&lt;BR /&gt;&lt;BR /&gt;Quick bit of perl would also do it:&lt;BR /&gt;&lt;BR /&gt;perl -e '{use Time::Local;($y,$mo,$d,$h,$mi)=split /:| |-/,shift;print time-timelocal(0,$mi,$h,$d,$mo-1,$y-1900),"\n";}' "2002-12-11 11:22"&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin.</description>
      <pubDate>Wed, 11 Dec 2002 11:23:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calculate-time-difference-in-unix-shell-script/m-p/2861738#M820785</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2002-12-11T11:23:11Z</dc:date>
    </item>
  </channel>
</rss>

