[Info-vax] check date against an given age
Ken Fairfield
ken.fairfield at gmail.com
Wed Nov 11 12:50:32 EST 2009
On Nov 11, 8:37 am, DTL <didier.mora... at gmail.com> wrote:
> Hi Folks,
>
> I'm needing some help to write the following in DCL:
>
> if person's age >= 60 years old then...
>
> knowning that birth date in file has format JJ/MM/AA
Assuming, as Jan-Erik asked, that JJ/MM/AA is day-month-year
(in english), a little use of F$CvTime and F$Element will do the
trick. :-)
I am making one assumption, possibly not justified, that
the output of F$CvTime("TODAY",,"DATE"), for example,
is in yyyy-mm-dd format. It may be that this format
is, or can be, overridden by the system manager...I was
looking at LIB$DT_STARTUP.COM and the
LIB$DATE_FORMAT_xx logical names, but I've forgotten
how and when one works these into DCL...
In any case, the first step is to form the comparison
date the represents 60 years before today. That's
pretty easy:
$ now = F$CvTime("TODAY",,"DATE")
$ y60 = F$Integer(F$Element(0, "-", now)) - 60
$ d60 = "''y60'-''F$Element(1,"-",now)'-''F$Element(2,"-",now)'"
(Please use a font that distinguishes the quotation mark, ",
from the double-apostrophes, '', in the above...)
Next you simply put the JJ/DD/AA date you've read into
standard comparison format. You probably need to check
of year-2000 issues cases given the AA format. Given
the input date is read into a DCL symbol jda, something
like:
$ this_aa = F$Element(2, "/", jda)
$ If this_aa.Gts."10"
$ Then
$ this_aa = "19" + this_aa
$ Else
$ this_aa = "20" + this_aa
$ Endif
$ this_date = this_aa + "-" + -
F$Element(1, "/", jda) + "-" +-
F$Element(0, "/", jda)
$
$ If d60.Ges.this_date
$ Then
$ Write Sys$Output "He's at least 60 years old!"
$ Endif
It's a shame that DCL doesn't include an easy
way to convert to and from different time formats.
You can do that in a compiled language using
the various LIB$DT routines. Nevertheless,
it's not so hard to do "by hand" using F$Element
and friends.
-Ken
More information about the Info-vax
mailing list