<?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: Date Calculations in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602283#M853115</link>
    <description>Hi Again,&lt;BR /&gt;&lt;BR /&gt;I thought I would also attach the script I use to test caljd.sh (caljdtest.sh). It runs cajld.sh through all of its arguments plus converts dates to Julian dates and back and compare them. The process must be reversible or there is an error. You can basically use this to see more ways to do your date calculations. There is also a JulianDate module in perl that works well.&lt;BR /&gt;&lt;BR /&gt;Clay</description>
    <pubDate>Fri, 26 Oct 2001 18:09:31 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-10-26T18:09:31Z</dc:date>
    <item>
      <title>Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602279#M853111</link>
      <description>Hello everyone,&lt;BR /&gt;&lt;BR /&gt;I am working on a script which generates a report. I need to know the dates 30, 60, 90, and 120 days from a given date &lt;BR /&gt;unless any of those dates fall on a weekend or a holiday. In that case, I would like to skip to the next regular working day.&lt;BR /&gt;&lt;BR /&gt;I have been trying to use the date command but that does not work very well so far. The ideal command would be something&lt;BR /&gt;like "future 12/20/2001 30" and would return 01/21/2002.  Thirty days from 12/20/2001 is actually 01/19/2002 but that is on a Saturday so I want it to skip to  the following Monday.&lt;BR /&gt;&lt;BR /&gt;Can anybody help?&lt;BR /&gt;&lt;BR /&gt;Thanks, Doug</description>
      <pubDate>Fri, 26 Oct 2001 15:24:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602279#M853111</guid>
      <dc:creator>Doug Dell</dc:creator>
      <dc:date>2001-10-26T15:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602280#M853112</link>
      <description>Here are some variables based on a script I used to calculate dates based on the epoch.&lt;BR /&gt;If you can figure out your current epoch date these should lead you down the right road. You can use the adb command to convert epoch to readable time.&lt;BR /&gt;&lt;BR /&gt;NINETY='7776000'&lt;BR /&gt;SIXTY='5184000'&lt;BR /&gt;THIRTY='2592000' &lt;BR /&gt;FORMULA=`echo "0d$NUMBER=Y" | adb`&lt;BR /&gt;NDAYS=`expr $CURRENT - $NINETY`&lt;BR /&gt;SDAYS=`expr $CURRENT - $SIXTY`&lt;BR /&gt;TDAYS=`expr $CURRENT - $THIRTY`&lt;BR /&gt;&lt;BR /&gt;Hope this is a step in the right direction...</description>
      <pubDate>Fri, 26 Oct 2001 15:32:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602280#M853112</guid>
      <dc:creator>Craig Rants</dc:creator>
      <dc:date>2001-10-26T15:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602281#M853113</link>
      <description>Hi doug,&lt;BR /&gt;&lt;BR /&gt;To do any kind of date manipulations, the easiest way i have found is to use Clay's caljd.sh script.&lt;BR /&gt;&lt;BR /&gt;You can download the latest from &lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6901c7af36b7d5118ff10090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6901c7af36b7d5118ff10090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;this script works and should get you started (uses the caljd.sh script)&lt;BR /&gt;&lt;BR /&gt;/Begin/&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;# USAGE: future.sh 12 20 2001 30&lt;BR /&gt;# future.sh mm dd yyyy increment_in_days&lt;BR /&gt;# future.sh 12 20 2001 30&lt;BR /&gt;# future.sh 12 20 2001 60&lt;BR /&gt;&lt;BR /&gt;PATH=/usr/bin:/usr/local/bin&lt;BR /&gt;&lt;BR /&gt;DATE1=$(caljd.sh $1 $2 $3)&lt;BR /&gt;&lt;BR /&gt;DAYS=$4&lt;BR /&gt;&lt;BR /&gt;WK_DAY=$(caljd.sh -w $(caljd.sh -n $DAYS $DATE1))&lt;BR /&gt;echo "wk day is $WK_DAY"&lt;BR /&gt;&lt;BR /&gt;if [ $WK_DAY -ge 1 -a $WK_DAY -le 5 ]&lt;BR /&gt;then&lt;BR /&gt;    FUTURE_DATE=$(caljd.sh -n $DAYS $DATE1)&lt;BR /&gt;    echo $FUTURE_DATE&lt;BR /&gt;&lt;BR /&gt;elif [ $WK_DAY -eq 6 ]&lt;BR /&gt;then&lt;BR /&gt;    FUTURE_DATE=$(caljd.sh -n $DAYS $DATE1+2)&lt;BR /&gt;    echo $FUTURE_DATE&lt;BR /&gt;&lt;BR /&gt;elif [ $WK_DAY -eq 0 ]&lt;BR /&gt;then&lt;BR /&gt;    FUTURE_DATE=$(caljd.sh -n $DAYS $DATE1+1)&lt;BR /&gt;    echo $FUTURE_DATE&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;/End/&lt;BR /&gt;&lt;BR /&gt;If you want to give the date in mm/dd/yyyy format just change the above script to manipulate the input.&lt;BR /&gt;&lt;BR /&gt;I am attaching the caljd.sh script for your reference&lt;BR /&gt;&lt;BR /&gt;-HTH&lt;BR /&gt;Ramesh</description>
      <pubDate>Fri, 26 Oct 2001 16:45:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602281#M853113</guid>
      <dc:creator>linuxfan</dc:creator>
      <dc:date>2001-10-26T16:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602282#M853114</link>
      <description>Hi Doug:&lt;BR /&gt;&lt;BR /&gt;Since Ramesh mentioned the caljd.sh script, I suppose I should tell you what it does. It takes a calendar date and converts into a fairly large integer called a Julian Date or Julian Day. This is the method used by astromers to avoid messy calculations that might span hundreds of years. The JD is actually the number of days since ~4713BCE. The neat thing about this is that they count off sequentially so things like (JD + offset) mod 7 = day of week. The other neat thing is that leap years, century years, are taken into account.&lt;BR /&gt;&lt;BR /&gt;Questions very similar to yours have appeared fairly recently and the one that piqued my interest was needing to calculate yesterday's&lt;BR /&gt;date unless it were on the weekend in which case return the previous Friday. This is essentially your problem in reverse. I had been working on an improved version that would do this without any outside calculations. I think I have it:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;MDY="12 21 2001"&lt;BR /&gt;&lt;BR /&gt;NEXT=30&lt;BR /&gt;N30=$(caljd.sh $(caljd.sh -n ${NEXT} -x 6 -x 0 ${MDY}))&lt;BR /&gt;echo "${MDY} + ${NEXT} days skipping over weekends is ${N30}."&lt;BR /&gt;&lt;BR /&gt;Note the nested caljd.sh calls. The inner one takes MDY (12 21 2001) and adds 30 days to it (-n ${NEXT}. If the final date falls on Sat. (-x 6) or Sun. (-x 0) skip to the next unexcluded weekday and output the Julian Day. The Julian Day is then converted by the outer caljd.sh call back into a calendar date. &lt;BR /&gt;&lt;BR /&gt;The format is MM DD YYYY rather than MM/DD/YYYY but everything else is about what you wanted. It doesn't do the holidays but back in the dawn of UNIX I seem to remember a holidays program and a holidays file. Maybe someone will remember what that was or I can find. If so, I may add that as to the script at some point. The important point is that all of your request now becomes a one-liner in the shell (except for holidays).&lt;BR /&gt;&lt;BR /&gt;If you invoke caljd.sh -u, it will print a usage message to stderr. I added some options to allow yyyy mm dd output and dd mm yyyy output as well as outputs without spaces because there were some requests for filename generation.&lt;BR /&gt;&lt;BR /&gt;There are quite a few features added to this version rather than the earlier version which Ramesh posted.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Clay&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Oct 2001 17:54:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602282#M853114</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-26T17:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602283#M853115</link>
      <description>Hi Again,&lt;BR /&gt;&lt;BR /&gt;I thought I would also attach the script I use to test caljd.sh (caljdtest.sh). It runs cajld.sh through all of its arguments plus converts dates to Julian dates and back and compare them. The process must be reversible or there is an error. You can basically use this to see more ways to do your date calculations. There is also a JulianDate module in perl that works well.&lt;BR /&gt;&lt;BR /&gt;Clay</description>
      <pubDate>Fri, 26 Oct 2001 18:09:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602283#M853115</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-26T18:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602284#M853116</link>
      <description>Hi Clay:&lt;BR /&gt;&lt;BR /&gt;I think the file you are looking for is :&lt;BR /&gt;&lt;BR /&gt;/etc/acct/holidays&lt;BR /&gt;/usr/sbin/acct/holidays&lt;BR /&gt;&lt;BR /&gt;They're part of the accounting module.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 26 Oct 2001 18:09:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602284#M853116</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-26T18:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602285#M853117</link>
      <description>Thanks Jim, I haven't had a request for accounting in so many moons that I had forgotten. I would give you some points but ...&lt;BR /&gt;&lt;BR /&gt;Doug, give this boy some points.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay</description>
      <pubDate>Fri, 26 Oct 2001 18:18:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602285#M853117</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-26T18:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602286#M853118</link>
      <description>Thanks everybody! This is great stuff. Clay, I just wish I understood how this works. Honestly, my shell script had grown to over 600 lines and still wasn't working correctly. I just ran your testscript and I was amazed. It even knew that 2000 was a leap year even if it was a century year!!! I guess I'll have to do the holidays but thank you.&lt;BR /&gt;&lt;BR /&gt;Best wishes, Doug</description>
      <pubDate>Fri, 26 Oct 2001 18:49:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602286#M853118</guid>
      <dc:creator>Doug Dell</dc:creator>
      <dc:date>2001-10-26T18:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602287#M853119</link>
      <description>Hi Doug:&lt;BR /&gt;&lt;BR /&gt;All of the real work of this this is done in just two awk functions CAL_JDATE which converts a calendar date to a Julian Day and JDATE_CAL which does the reverse. In fact, the bulk of the code is command line argument processing, usage messages, and a shell function to skip over the excluded weekdays.&lt;BR /&gt;&lt;BR /&gt;The CAL_JDATE function is actually a one-liner; get out your calculator and try it but remember to use integer arithmetic and throw away any fractional results. I had a bug in an earlier version because like an idiot I missed one. &lt;BR /&gt;&lt;BR /&gt;The JDATE_CAL is more difficult and I gave up on making it a one-liner. You can take out your calculator and step through it as well.&lt;BR /&gt;&lt;BR /&gt;I suppose the neatest thing about these routines is that they don't use a single IF statement and yet they are able through the magic of integer arithmetic to do the 'Thirty days hath September ...' month calculations. I can't take credit for the Julian Days calculations; they've been around a very long time - back to the days when computers were people. I should also point out that real Julian Dates are floating point values that include the fractional part of each day and begin at noon UTC. That way, the astronomical 'day' doesn't have to worry about events occuring on different days and nobody worries about Daylight Saving Time. All astromical events are published only in UTC and Julian Date values to avoid the confusion of "what time is it?" and "where am i?".&lt;BR /&gt;&lt;BR /&gt;By the way if you feel up to it, by all means add the holidays Jim cited and post the resulting script. That's how the forums become a valued added product.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Oct 2001 19:19:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602287#M853119</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-26T19:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602288#M853120</link>
      <description>Hi Doug:&lt;BR /&gt;&lt;BR /&gt;I spent a few minutes over the weekend and today adding the holidays exclusion to caljd.sh (Vrsn 2.01). Believe it or not, I actually had a need for it. The guy who does the tape exports from the library for offsite storage had asked me about a year ago if I couldn't make the return tape (which is normally 7 days from now) also skip over holidays. Anyway -x 6 -x 0 -h will skip Saturdays, Sundays, and holidays as defined in the file Jim dug up: /etc/acct/holidays. I had to make a slight modification in case the year's cross, it looks in /etc/acct/holidays_yyyy (e.g.) /etc/acct/holidays_2002 for holidays outside the current year. This will in no way interfere with the normal usage of the file. You simply have to create the holidays file and caljd.sh will now take care of the rest.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Oct 2001 23:58:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602288#M853120</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-29T23:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602289#M853121</link>
      <description>Thanks Clay. This appears to be just what I needed! The only holidays file I have is for 1996. Obviously this isn't being used. Can I just change this one?&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Tue, 30 Oct 2001 13:31:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602289#M853121</guid>
      <dc:creator>Doug Dell</dc:creator>
      <dc:date>2001-10-30T13:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602290#M853122</link>
      <description>Hi Doug:&lt;BR /&gt;&lt;BR /&gt;'/etc/acct/holidays' can/should be edited to your tastes.  The '/usr/sbin/acct/holidays' file I pointed out originally is but a link to the file in /etc.&lt;BR /&gt;&lt;BR /&gt;You always have a virgin copy of the holidays file as '/usr/newconfig/etc/acc&lt;BR /&gt;t/holidays'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 30 Oct 2001 13:44:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602290#M853122</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-30T13:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602291#M853123</link>
      <description>Well you could; however, if you are really going to use this as I intended, you should do this:&lt;BR /&gt;&lt;BR /&gt;1) Create a current file e.g. /etc/acct/holidays_2001.&lt;BR /&gt;2) mv /etc/acct/holidays /etc/acct/holidays_1996&lt;BR /&gt;3) ln -s /etc/acct/holidays_2001 /etc/acct/holidays&lt;BR /&gt;&lt;BR /&gt;When each new year rolls around, create a new symbolic link between the holidays_yyyy file and the holidays file. That way, if you use accounting (which you obviously do not); the accounting system continues to work as before.&lt;BR /&gt;I trust you have figured out that you can use caljd.sh to calculate the days offset for the holidays file entries. If you don't have a holidays file for a given year but you have specified the -h option to skip holidays, caljd.sh will not consider this an error. It first tests for the existence of the indicated holidays files. If not found, it just goes on its merry way and assumes that you intentionally did not create a holidays file for a given year.&lt;BR /&gt;&lt;BR /&gt;You might want to add a cron entry that sends you a reminder at the end of the year to update /etc/acct/holidays file. Systems which actually use accounting have that as a normal crontab entry. &lt;BR /&gt;&lt;BR /&gt;Regards, Clay</description>
      <pubDate>Tue, 30 Oct 2001 13:45:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602291#M853123</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-30T13:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculations</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602292#M853124</link>
      <description>Thanks guys! That really helped. I continue to be amazed at the amount of expertise that I find on these forums.&lt;BR /&gt;&lt;BR /&gt;Thanks for everything, Doug.&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Oct 2001 14:01:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/date-calculations/m-p/2602292#M853124</guid>
      <dc:creator>Doug Dell</dc:creator>
      <dc:date>2001-10-30T14:01:39Z</dc:date>
    </item>
  </channel>
</rss>

