<?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 calculate time difference in Shell in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260617#M888367</link>
    <description>Well the first of the month is rather easy:&lt;BR /&gt;&lt;BR /&gt;DAY=$(date '%M');&lt;BR /&gt;if [[ "${DAY}" = "01" ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "First Day"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;However, the general answer to how to manipulate date ranges is the use of this script that someone wrote called caljd.sh. &lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;This will return the date 3 days from now in MM DD YYYY format:&lt;BR /&gt;DT=$(caljd.sh $(caljd.sh -n 3))&lt;BR /&gt;echo "Date = ${DT}"&lt;BR /&gt;&lt;BR /&gt;If all you wanted was the month 3 days from now that would be:&lt;BR /&gt;MO=$(caljd.sh -M $(caljd.sh -n 3))&lt;BR /&gt;echo "Month = ${MO}"&lt;BR /&gt;&lt;BR /&gt;Invoke as caljd.sh -u for full usage and examples.&lt;BR /&gt;</description>
    <pubDate>Tue, 27 Apr 2004 17:21:05 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2004-04-27T17:21:05Z</dc:date>
    <item>
      <title>how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260614#M888364</link>
      <description>Is it possible to calcuate time difference in UNIX shell:&lt;BR /&gt;&lt;BR /&gt;for example:&lt;BR /&gt;&lt;BR /&gt;System_Time = 4:36:00PM&lt;BR /&gt;&lt;BR /&gt;My_Time = 9:00:00PM&lt;BR /&gt;&lt;BR /&gt;Can I get something like this..&lt;BR /&gt;&lt;BR /&gt;My_Time - System_Time &lt;BR /&gt;&lt;BR /&gt;I need to check whether this time interval is enough to execute a batch job.&lt;BR /&gt;&lt;BR /&gt;Thank You,&lt;BR /&gt;Suman</description>
      <pubDate>Tue, 27 Apr 2004 12:22:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260614#M888364</guid>
      <dc:creator>Suman_7</dc:creator>
      <dc:date>2004-04-27T12:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260615#M888365</link>
      <description>The best way is to convert everything to seconds using a function:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;get_seconds()&lt;BR /&gt;{&lt;BR /&gt;  typeset -i10 HR=${1}&lt;BR /&gt;  typeset -i10 MIN=${2}&lt;BR /&gt;  typeset -i10 SEC=${3}&lt;BR /&gt;  shift 3&lt;BR /&gt;  typeset -i10 TOT=$(( (${HR} * 3600) + (${MIN} * 60) + ${SEC} ))&lt;BR /&gt;  echo "${TOT}"&lt;BR /&gt;  return 0&lt;BR /&gt;} # get_seconds&lt;BR /&gt;&lt;BR /&gt;typeset -i10 H1&lt;BR /&gt;typeset -i10 M1&lt;BR /&gt;typeset -i10 S1&lt;BR /&gt;&lt;BR /&gt;date '+%H %M %S' | read H1 M1 S1&lt;BR /&gt;&lt;BR /&gt;typeset -i10 H2=21&lt;BR /&gt;typeset -i10 M2=0&lt;BR /&gt;typeset -i10 S2=0&lt;BR /&gt;&lt;BR /&gt;typeset -i10 DIFF=$(( $(get_seconds ${H2} ${M2} ${S2}) - $(get_seconds ${H1} ${M1} ${S1}) ))&lt;BR /&gt;echo "Time left = ${DIFF} seconds"&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Apr 2004 12:38:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260615#M888365</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-27T12:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260616#M888366</link>
      <description>That worked wonderfully Thank You. Can you answer one more question..&lt;BR /&gt;&lt;BR /&gt;How do I find if the parameter_date falls on the 1st day of the month in UNIX.&lt;BR /&gt;&lt;BR /&gt;I have to check for a condition if the parameter_date is the 1st day of any of the 12 months.&lt;BR /&gt;&lt;BR /&gt;Is it possible in UNIX to manipulate dates for example increment date by 1 day?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Suman&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Apr 2004 17:07:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260616#M888366</guid>
      <dc:creator>Suman_7</dc:creator>
      <dc:date>2004-04-27T17:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260617#M888367</link>
      <description>Well the first of the month is rather easy:&lt;BR /&gt;&lt;BR /&gt;DAY=$(date '%M');&lt;BR /&gt;if [[ "${DAY}" = "01" ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "First Day"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;However, the general answer to how to manipulate date ranges is the use of this script that someone wrote called caljd.sh. &lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;This will return the date 3 days from now in MM DD YYYY format:&lt;BR /&gt;DT=$(caljd.sh $(caljd.sh -n 3))&lt;BR /&gt;echo "Date = ${DT}"&lt;BR /&gt;&lt;BR /&gt;If all you wanted was the month 3 days from now that would be:&lt;BR /&gt;MO=$(caljd.sh -M $(caljd.sh -n 3))&lt;BR /&gt;echo "Month = ${MO}"&lt;BR /&gt;&lt;BR /&gt;Invoke as caljd.sh -u for full usage and examples.&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Apr 2004 17:21:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260617#M888367</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-27T17:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260618#M888368</link>
      <description>Oops,&lt;BR /&gt;No semicolon at the end:&lt;BR /&gt;DAY=$(date '%M');&lt;BR /&gt;should be&lt;BR /&gt;DAY=$(date '%M')</description>
      <pubDate>Tue, 27 Apr 2004 17:23:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260618#M888368</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-27T17:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260619#M888369</link>
      <description>Thanks for your reply..&lt;BR /&gt;&lt;BR /&gt;I tried this script but it gives me error:&lt;BR /&gt;date: bad conversion&lt;BR /&gt;&lt;BR /&gt;#####################&lt;BR /&gt;DAY=$(date '%M')&lt;BR /&gt;if [[ "${DAY}" = "28" ]]&lt;BR /&gt;then&lt;BR /&gt;echo "Twenty Eight Day"&lt;BR /&gt;fi&lt;BR /&gt;######################&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Suman&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 09:55:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260619#M888369</guid>
      <dc:creator>Suman_7</dc:creator>
      <dc:date>2004-04-28T09:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260620#M888370</link>
      <description>Missing the '+' in the format.&lt;BR /&gt;&lt;BR /&gt;DAY=$(date '+%M')&lt;BR /&gt;&lt;BR /&gt;Do a "man date"; it explains all of your options.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 09:58:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260620#M888370</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-28T09:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260621#M888371</link>
      <description>I tried this it works now:&lt;BR /&gt;&lt;BR /&gt;DAY=`date +%d`&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Suman</description>
      <pubDate>Wed, 28 Apr 2004 10:03:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260621#M888371</guid>
      <dc:creator>Suman_7</dc:creator>
      <dc:date>2004-04-28T10:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260622#M888372</link>
      <description>Is it possible to use caljd.ksh to convert a specific parameter to 1 day back&lt;BR /&gt;for example..&lt;BR /&gt;&lt;BR /&gt;parm_date=20040501&lt;BR /&gt;&lt;BR /&gt;If the parameter date is first of month&lt;BR /&gt;then change this parameter date to 1 day back. Actually I need to pass parm_date=20040430 as my argument.&lt;BR /&gt;&lt;BR /&gt;Also my date in the format yyyymmdd with no spaces.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot&lt;BR /&gt;Suman</description>
      <pubDate>Wed, 28 Apr 2004 10:18:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260622#M888372</guid>
      <dc:creator>Suman_7</dc:creator>
      <dc:date>2004-04-28T10:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate time difference in Shell</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260623#M888373</link>
      <description>Suman,&lt;BR /&gt;&lt;BR /&gt;If you have a lot of those jobs to do, GNU date would make it easy. It offers the same fetures as your date command, but adds somes :&lt;BR /&gt;. converting a date (for example to epoch, that will let you make differences)&lt;BR /&gt;. have date for yesterday or n days ago&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 10:18:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-calculate-time-difference-in-shell/m-p/3260623#M888373</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2004-04-28T10:18:36Z</dc:date>
    </item>
  </channel>
</rss>

