- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Calculate no. of days
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2005 06:49 AM
тАО05-13-2005 06:49 AM
Anyone has program to calculate no. of days between two date. I want to use it in DCL program.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2005 07:24 AM
тАО05-13-2005 07:24 AM
Solutionupgrade to V7.3-2, and you will have F$DELTA_TIME
If you can not, a little DCL can do (we had it for years):
$ diff = 0
$ ldat=f$cvtim("
$loop:
$ if f$cvtim("first_date+''diff'-","comparison","date") .lts. ldat
$ then
$ diff=diff+1
$ goto loop
$ endif
Sorry, indentation gets lost by forum makeup :-(
Proost.
Have one on me.
jpe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2005 08:58 AM
тАО05-13-2005 08:58 AM
Re: Calculate no. of days
$! DELTA_DAYS.COM original by J. FINKA Nov 1990
$! assume p1 <= p2 and delta < 9999
$ p2 = f$cvtime(p2,"absolute","date") !normalize
$ years = 'f$cvtime(p2,,"year") - 'f$cvtime(p1,,"year")
$ months = 'f$cvtime(p2,,"month") - 'f$cvtime(p1,,"month")
$ days = 'f$cvtime(p2,,"day") - 'f$cvtime(p1,,"day")
$ y = (36525 * years + 3044 * months) / 100 + days
$ i = 0
$ l: x = y + i
$ i = - i
$ if i .ge. 0 then i = i + 1
$ q = f$cvtime(p1 + " +" + f$string(x) + "-","absolute","date")
$ if q .nes. p2 then goto l
$ write sys$output "Delta days : ", x
$ @delta_days 01-jan-2001 01-jan-2005
Delta days : 1461
And one of many possible perl implemenations.
Calculate each date in seconds, subtract and divide by seconds in a day:
$ type delta_days.p
use Time::Local;
$_ = shift @ARGV;
if (/(\d{4})-(\d+)-(\d+)/) {
$d1 = timelocal(0,0,0,$3,$2-1,$1-1900);
} else {die "please provide date 1 as YYYY-MM-DD"};
$_ = shift @ARGV;
if (/(\d{4})-(\d+)-(\d+)/) {
$d2 = timelocal(0,0,0,$3,$2-1,$1-1900);
} else {die "please provide date 2 as YYYY-MM-DD"};
$days = ($d1 - $d2) / (24*60*60);
print "$days days";
$ perl delta_days.p 2005-1-1 2001-1-1
1461 days
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2005 09:41 AM
тАО05-13-2005 09:41 AM
Re: Calculate no. of days
Yes,
our _operational_ routine also had 1000 day steps with backtrack, then 100's, then 10's. but I did I Q & D re-create from memory...
And like any example given here:
A - use at own risk
B - use as starting point, take the idea & refine it.
cu in Nashua, I guess?
Proost.
Have one on me.
jpe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2005 09:12 PM
тАО05-13-2005 09:12 PM
Re: Calculate no. of days
here there is a dcl proceure I converted from a my C program.
This procedure takes any date in dcl format (dd-mmm-yyyy) and converts it in julien date. Julien date is the number of days since a specific date. Within julien date you can add or subtract two dates.
Original routine works since 01-01-0000 but this dcl procedure works only since 1924 (read header for furthermore information).
Hope this help
Antonio Vigliotti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2005 08:25 PM
тАО05-15-2005 08:25 PM
Re: Calculate no. of days
If you want a program to do this, ICALC (http://nucwww.chem.sunysb.edu/htbin/software_list.cgi?package=icalc) converts between Julian dates, so could be used to compare the two.
Robert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2005 07:41 PM
тАО05-16-2005 07:41 PM
Re: Calculate no. of days
starting with VMS 8.2 you can use the lexical Function F$DELTA:
$ write sys$output F$DELTA("01-JAN-2001","01-JAN-2005")
1461 00:00:00.00
Bye Kuddel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2005 08:07 PM
тАО05-16-2005 08:07 PM
Re: Calculate no. of days
like I already wrote in my first reply, F$DELTA is there since V7.3-2 (to be precise, in the DCL patch)
Proost.
Have one on me.
jpe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 12:28 AM
тАО05-17-2005 12:28 AM
Re: Calculate no. of days
1) the 2 dates must be in the same year to allow + - operations.
2) leap years are not supported (29 days in feb)
Wim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2005 01:05 AM
тАО05-17-2005 01:05 AM
Re: Calculate no. of days
Wim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2005 06:35 PM
тАО05-18-2005 06:35 PM
Re: Calculate no. of days
to be clear, dcl routine is convertion of C program. Original program is more complex because manage all dates since 01-01-0000 until today, calculating leap year and missed day in 1582 (Italy, France, Spain). C program is certified by a complex test unit. I removed complex calculation for missed days of 1582 and other minor feature so dcl routine is simple to write and easy to execute. I didn't remove leap year calculation therefore conversion works fine since 01-01-1925 for every country.
Antonio Vigliotti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2005 06:37 PM
тАО05-18-2005 06:37 PM
Re: Calculate no. of days
Just test it with the diff between 28-feb and 1-mar. It's always going to return 1, even for leap years.
Wim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2005 09:31 PM
тАО05-18-2005 09:31 PM
Re: Calculate no. of days
I made an executable f$delta_time for pre-7.3-2.
Look at it in f$delta_time.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2005 09:39 PM
тАО05-18-2005 09:39 PM
Re: Calculate no. of days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2005 11:08 PM
тАО05-18-2005 11:08 PM
Re: Calculate no. of days
since it's different in every other forum:
to put such a link here in ITRC forum, is it enough to put the URL, not the
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2005 11:10 PM
тАО05-18-2005 11:10 PM
Re: Calculate no. of days
Wim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2005 01:09 AM
тАО05-19-2005 01:09 AM
Re: Calculate no. of days
I'm sorry to also report that your DCL example is truly broken. You may want to verify that the C program was correct to begin with.
- As reported, it does not really do leapyears.
- It also 'lucks out' that 2000 actually was a leap year unlike 1900 and 2100
- It fails to accept input like 01-feb 01-apr because 'apr' is less than 'feb' in text form.
- It fails to accept 28-feb-2005 01-mar-2005 because 01 sorts befor 28 in text form.
- The days-so-far-in-this-year calculation uses a clumsy loop while you can just lookup the startdays of each month in the table instead of using the number of days in the table.
btw... I used a perl one-liner to make that new lis from your list:
$ perl -e "foreach (qw(0 31 28 31 30 31 30 31 31 30 31 30 31)) { $x +=$_; print "",$x"" }"
,0,31,59,90,120,151,181,212,243,273,304,334,365
The update code below seems to work.
Regards,
Hein.
$! Convertion date from DCL format to julien format
$! Author: Antonio Vigliotti antoniov@shs-av.it
$! Tweaks by Hein van den Heuvel
$! Julien date is the number of days since 1-1-0
$! Converted from a C routine
$! Original routine calculate change of calendar by pope Gregor XIII in
$! year 1582. Therefor this DCL routine works only since 1582 (in Italy)
$! or since 1824 (in Greek). For other countries read history!
$! Julien date can be use to compare two dates.
$begdat=p1
$enddat=p2
$if p2.nes."" then goto mloop1
$mloop:
$ inquire begdat "Beg.Date [dd-mmm-yyyy]"
$ if begdat.eqs."" then exit
$ inquire enddat "End Date [dd-mmm-yyyy]"
$ if enddat.eqs."" then exit
$mloop1:
$ if f$cvt(enddat).lts.f$cvt(begdat) then goto mloop
$ dt=begdat
$ gosub c2julien
$ begj=j
$ dt=enddat
$ gosub c2julien
$ endj=j
$ write sys$output enddat," - ",begdat," = ",endj-begj
$if p2.nes."" then exit
$ goto mloop
$c2julien:
$ y=f$cvtime(dt,,"year")
$ m=f$cvtime(dt,,"month")
$ days = "0,0,31,59,90,120,151,181,212,243,273,304,334"
$! Good untill 2100. Need 100/400 year rule after that
$ j=y*365 + (y+3)/4 + 'f$elem(m,",",days) + 'f$cvtim(dt,,"day")
$if m.gt.2 then j = j + 3 - f$cvtim("28-FEB-''y' +1-",,"MONTH") ! Leap?
$ return
--------------------
$ @tmp 28-feb-2004 01-mar-2004
01-MAR-2004 - 28-FEB-2004 = 2
$ @tmp 28-feb-2005 01-mar-2005
01-MAR-2005 - 28-FEB-2005 = 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2005 07:47 PM
тАО05-19-2005 07:47 PM
Re: Calculate no. of days
I worked too hurry :-(
Now, attachment is right routine. It works with leap year since 1582 in Italy, Spain and France. Since 1711 in UK, 1918 in Russia, 1925 in Greek.
I checked accurately original c routine so DCL is more complex.
I converted part of C test unit. Now you see test since 01-01-1900 until 31-12-2005.
Julien calculate yeap year every 4 years but not every century but every 400 years.
Before 15-10-1582 (in Italy, ...) yeap year was every 4 years. Pope Gregorio XIII changed calendar missed 10 days. England corrected calendar on 1710, Russia after revolution of 1917.
For furthermore information ask me.
Antonio Vigliotti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2005 07:53 PM
тАО05-19-2005 07:53 PM
Re: Calculate no. of days
Original C routine is not translated in english language so you can understand by C source code.
All routine are certificated by a very complex test unit (not attacched).
You can ask me for every information.
Thanks to Wim and Hein for their warning.
Antonio Vigliotti