Operating System - OpenVMS
1753854 Members
7121 Online
108808 Solutions
New Discussion юеВ

Converting COMPARISON to ABSOLUTE time

 
SOLVED
Go to solution
Jack Trachtman
Super Advisor

Converting COMPARISON to ABSOLUTE time

Hopefully I'm just missing something obvious, but I don't see a DCL lexical func that will convert COMPARSION time back to ABSOLUTE time.

I often store COMPARISON times in records so that I can, well, compare times. Now, I'd like be able to use some the F$CVTIME options to get WEEKDAY, etc, but don't see an easy way to convert the time back to ABSOLUTE, which F$CVTIME seems to require. (Also - I noticed that the F$DELTA lexical only uses ABSOLUTE times).
12 REPLIES 12
EdgarZamora
Trusted Contributor

Re: Converting COMPARISON to ABSOLUTE time

Not sure exactly what you're asking, but f$cvtime is capable of outputting absolute time. "ABSOLUTE" in the second argument which is the output time format.
Dean McGorrill
Valued Contributor

Re: Converting COMPARISON to ABSOLUTE time

it will do absolute, here a what day I
use. Dean
**********
$!
$! whatday.com dean mcgorrill 08-mar-2007
$!
$! return weekday and time, pass a date via p1 parameter
$!
$ wo=="write sys$output"
$ daytime = f$cvtime(p1,,"weekday") + " " + -
f$cvtime(p1,"absolute","datetime")
$ daytime = f$extract(0,f$locate(".",daytime),daytime)
$ wo daytime
$ exit 1
Robert Gezelter
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

Jack,

Interesting. This seems to be an error in the documentation that was fixed sometime between Version 6.2 and Version 8.2 (I do not have the time to narrow it further).

Off the top of my head, given the fact that F$CVTIME does not do it directly, I would engage in a little slight of hand. F$CVTIME is still known to work for DELTA and combination times. I would use F$ELEMENT to extract the year, insert it into a January 1, xxxx absolute date and use the rest of the comparison date to create a delta time, using F$CVTIME to then get the various components.

If I am not being clear, please let me know.

- Bob Gezelter, http://www.rlgsc.com
Jon Pinkley
Honored Contributor
Solution

Re: Converting COMPARISON to ABSOLUTE time

Jack,

You are not missing anything, there is no lexical function to convert from ABSOLUTE format to DELTA format (at least not that I am aware of).

It can be done in one line of DCL, although it isn't pretty. Because the COMPARISON format is well defined, we can extract the year, and day without a problem, the trick is to convert the numerical month to the three character month name abreviation. The easiest way to do that is with the f$element function.

Here's the an example converting a comparision time in the symbol ct to an absolute time in symbol at.

Note: it does not handle DELTA times.

$ ct=f$cvtime("")
$ sho sym ct
CT = "2007-08-08 15:12:09.25"
$ at=f$extract(8,2,ct)+"-"+f$element(f$extract(5,2,ct),",",",JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC")+"-"+f$extract(0,4,ct)+f$extract(10,12,ct)
$ sho sym at
AT = "08-AUG-2007 15:12:09.25"

It would be nice to have an F$CVCOMPARISON_TIME or F$CVCTIME function with an optional "DCL" qualifier to place a ":" between the date and time.

Here's a more understandable version (not tested, just typed in)

$ dd = f$extract(8,2,ct)
$ mm = f$extract(5,2,ct)
$ mmm = f$element(mm,"|","|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC")
$ yyyy = f$extract(0,4,ct)
$ time = f$extract(11,11,ct)
$ at = dd + "-" + mmm + "-" + yyyy + " " + time

Jon
it depends
Jon Pinkley
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

What I meant was "there is no lexical function to comvert from COMPARISON time to ABSOLUTE time" Sorry for the confusion.

Jon
it depends
Hein van den Heuvel
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

Using DCL you'll have to hard-code the conversion. You can avoid coding up the month table by using a second line to grab the month and exploiting f$cvtime (as Bob suggests). The amount of typing is similar.

$ CT = "2007-01-01 15:12:09.25"
$ x = 31*f$extr(5,2,ct)-31
$ write sys$output f$extr(8,2,CT)+"-"+f$elem(1,"-",f$cvtime("1-JAN +''x'-","ABSOLUTE"))+"-"+f$extr(0,4,ct)+f$ext(10,99,ct)
01-JAN-2007 15:12:09.25

$ CT = "2007-12-31 15:12:09.25"
$ x = 31*f$extr(5,2,ct)-31
$ write sys$output f$extr(8,2,CT)+"-"+f$elem(1,"-",f$cvtime("1-JAN +''x'-","ABSOLUTE"))+"-"+f$extr(0,4,ct)
31-DEC-2007

The helper variable 'x' is a number of days since the start of the year garantueed to be in te right month, but an slowly increasing day in each month.

fwiw,
Hein.

Jack Trachtman
Super Advisor

Re: Converting COMPARISON to ABSOLUTE time

Thanks all.

You've confirmed what I found, and have given me some ideas.
Jon Pinkley
Honored Contributor

Re: Converting COMPARISON to ABSOLUTE time

After thinking a bit more about this, instead of a new lexical function, it would probably be better to modify f$cvtime to accept a fourth parameter, input-format, that would default to "ABSOLUTE" to be compatible with existing code.
Specifcally, it would be nice if the following was allowed and worked.

$ AT = lib$cvtime("2007-01-02 17:59:59.27","ABSOLUTE",,"COMPARISON") ! not implemented
$ show symbol at
AT = "02-JAN-2007 17:59:59.27" ! this is just a wishlist

Jon
it depends
Jack Trachtman
Super Advisor

Re: Converting COMPARISON to ABSOLUTE time

Jon,

I agree with your suggested addition, but I'd also like F$CVTIME and F$DELTA to accept any time format as input!