1748209 Members
2720 Online
108759 Solutions
New Discussion юеВ

Continuous day count

 
SOLVED
Go to solution
Niall76
Frequent Advisor

Continuous day count

Hi,

Is there some way in VMS of getting the number of days since a certain date to today? To be precise the number of days since the 10th of April 1988 to today. I currently use a simple excel spreadsheet and enter the value myself, but if VMS can calculate this number for me it would be great.

Kind Regards,

Niall
22 REPLIES 22
Joseph Huber_1
Honored Contributor

Re: Continuous day count


See HELP LEXICAL F$DELTA_TIME.

If You have a system older than VMS 7.3-2 and a fortran compiler, then You may use my version at
http://wwwvms.mpp.mpg.de/~huber/util/main/f$delta_time.HTML

http://www.mpp.mpg.de/~huber
Niall76
Frequent Advisor

Re: Continuous day count

Hi Joseph,

Yes I'm only running version 7.3. I was hoping that this could be done using a Lexical function of some sort. Is this possible?

Regards and Thanks,

Niall
Joseph Huber_1
Honored Contributor

Re: Continuous day count

F$delta_time IS the lexical function You are asking for, but was introduced only with VMS 7.3-2.

So either use my replacement program, or search for some earlier DCL command-files doing the calculation in pure DCL, I think at dcl.openvms.org there was one posted.
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: Continuous day count

The DCL-only solution was posted by R.Boyd at

http://dcl.openvms.org/stories.php?story=07/01/16/4051929
http://www.mpp.mpg.de/~huber
Niall76
Frequent Advisor

Re: Continuous day count

Thanks Joseph for everything so far, but please can you help me with this Com file. I can't seem to be able to enter in the required paramters correctly. I'm sure I'm making a hash of it.
This is what I enter and get nothing back at all, not even an error:
@time_difference.com; 16-JAN-2008:13:40:00 DELTA_TIME "TIME" 16-JAN-2007:13:40:00

Thanks again,
Niall
Joseph Huber_1
Honored Contributor
Solution

Re: Continuous day count

For me it works:

@time_difference 16-JAN-2008:13:40:00 delta_time "TIME" 16-JAN-2007:13:40:00
sh sym delta_time
DELTA_TIME == "+364-00:00:00.00"

Lost something in downloading from dcl.openvms.org ?
http://www.mpp.mpg.de/~huber
Niall76
Frequent Advisor

Re: Continuous day count

Nope! I just never showed symbol afterwards.

So this works, kind off. for some reason the day i was in 1988 does not, but one year later it does. Any ideas?

Prompt> @time_difference 10-Apr-1989:12:00:00 delta_time "TIME" 8-FEB-2011:00:00:00
Prompt> sh sym DELTA_TIME
DELTA_TIME == "-7974-12:00:00.00"
Prompt> @time_difference 10-Apr-1988:12:00:00 delta_time "TIME" 8-FEB-2011:00:00:00
%DCL-W-IVATIME, invalid absolute time - use DD-MMM-YYYY:HH:MM:SS.CC format
\8-FEB-2011 00:00:00.00-16383-0:0\
%DCL-W-IVATIME, invalid absolute time - use DD-MMM-YYYY:HH:MM:SS.CC format
\8-FEB-2011 00:00:00.00-32767-0:0\

Thanks,
Niall
Hein van den Heuvel
Honored Contributor

Re: Continuous day count

The problem with F$DELTA is that it is limited to 9999 days... roughly 25 years.

So to use it properly you'd have to go through the years in chunks of less than 9999 days.
See example below.

Google finds a good few examples, and the TIME_DIFFERENCE one on OpenVMS.org is fine, but a bit much.
A cure but noisy, general purpose example is:
http://www.convertunits.com/dates/from/Nov+17,+1858/to/Feb+8,+2011

Brute forcing through the years and days instead of a binary search works fine as well, or you can just use math as in other examples.
The example below uses the fact the '29' it odd, thus has the low bit set, and thus is TRUE, whereas 28 is false, to adjust for leap years.

Below two examples to just calculate the days since a reference date (not before 17-NOV-1858).

You can edit in your own reference date to speed it up a little if need be.

Turn into a subroutine as needed to calculate a difference.

Hein

$ type DAY_SINCE_17_NOV_1858.com
$
$ target = 123 ! This integer will become a string if Convert time works
$ target = F$CVT(P1,"ABSOLUTE","DATE")
$ IF F$TYPE(target) .NES. "STRING" THEN EXIT 16
$ year = 1858
$ days = 45 - 365
$ target_year = 'F$CVT( target,,"YEAR")
$
$year_loop:
$ year = year + 1
$ days = days + 365
$ IF F$CVTIME("1-MAR-''year' -1-",,"DAY") THEN days = days + 1 ! 28=false, 29=true
$ IF year.LT.target_year THEN GOTO year_loop
$
$ date = "1-JAN-''year'"
$day_loop:
$ IF date .EQS.target THEN GOTO done
$ date = F$CVT("''date' +1-","ABSOLUTE","DATE")
$ days = days + 1
$ goto day_loop
$
$ done:
$ write sys$output p1, " is ", days, " days since 17-NOV-1858 "


For OpenVMS 7.3-2 or better with F$DELTA

$
$ target = 123 ! This integer will become a string if Convert time works
$ target = F$CVT(P1,"ABSOLUTE","DATE")
$ IF F$TYPE(target) .NES. "STRING" THEN EXIT 16
$ days = 0
$ start_date = "17-NOV-"
$ start_year = 1858
$ target_year = 'F$CVT( target,,"YEAR")
$ target_date = target - "''target_year'"
$chunck_loop:
$ IF ( target_year - start_year ) .LE. 25 THEN GOTO last_chunck
$ start_next = start_year + 25
$ days = days + f$elem(0," ",f$delta( start_date + "''start_year'", start_date + "''start_next'" ))
$ start_year = start_next
$ goto chunck_loop
$
$last_chunck:
$ dddd = f$delta( start_date + "''start_year'", target)
$ days = days + f$elem(0," ", f$edit( dddd, "TRIM" ))
$ write sys$output p1, " is ", days, " days since 17-NOV-1858 "







Niall76
Frequent Advisor

Re: Continuous day count

from 10-Apr-1988 to today is less than 9999, it is only 8340 by my calculations so the com file should still have worked, yes?

Just if it is fails with less than 9999, then it will probably fail also with looping it.

Maybe it possible to add a value to the returned DELTA_TIME. Say the number of days from 10-APR-1988 to 31-Jan-1999 and then add this number of days to the returned DELTA_TIME and use the start date to be 01-Jan-2000. How do i do that then... :)

Thanks,
Niall