[mod.computers.vax] date/time arithmetic in vms

gwalker@BBN-SPCA.ARPA (Gail Rubin Walker) (07/01/86)

If I want to compute a date (VAX quadword date form) that is 1 month from today
- what is the best way? It seems to me that there is a system service
'missing'. I can get the current date/time in a 7-word array with sys$numtim.
One of the words is month number.  I can add 1 to that (and do the appropriate
things if I've gone off the end of the year) but then what?  There doesn't
appear to be a service that converts from the 7 word array back to the vax
quadword format. Or even from the 7 word array to an ascii string. The other
system services that deal with quadword times convert from quadword to ascii
string and back - that doesn't help.  Do I really have to then myself turn the
7 word array into an ascii string to use sys$bintim to get back to the quadword
form? Or have I just overlooked a system routine somewhere?

-- Gail Walker
gwalker@bbn-spca

LEICHTER-JERRY@YALE.ARPA.UUCP (07/03/86)

    If I want to compute a date (VAX quadword date form) that is 1 month from
    today - what is the best way?
The quadword format is the one to work with; since it is a simple binary
number - yes, I know it's a quadword - you can do arithmetic on it:

	a)  Use $GETTIM to get the current time into quadword NOW.
	b)  Now you need, in quadword DELTA, a delta time that represents
		"one month".  Unfortunately, there is no notation for "plus
		one month" - only for "plus some number of days".  So you'll
		need to compute the number of days in the current month ("30
		days hath September, all the rest I don't remember", to quote
		Martin Minow) - call it dd - and convert the delta time
		"dd 00:00:00.00" into DELTA, again with $BINTIM.
	c)  The value you want is NOW - DELTA.  (It's "-" rather than "+"
		because delta times in quadword format are stored negated.)

That leaves the problem of doing quadword arithmetic, something no HLL does
directly.  However, there is a library procedure - LIB$SUBX - to do exactly
that.  The quadword values themselves your HLL program will consider to be
arrays of 2 longwords.

There is an alternative approach:  Rather than using $NUMTIM, use $ASCTIM.
The ASCII string you get back isn't nearly as convenient for manipulation as
the array $NUMTIM gives you, but you CAN convert it back with $BINTIM.

							-- Jerry
-------