[Info-vax] check date against an given age
Hein RMS van den Heuvel
heinvandenheuvel at gmail.com
Thu Nov 12 11:25:24 EST 2009
On Nov 12, 10:31 am, Mike Rechtman <m... at rechtman.com> wrote:
> Hein RMS van den Heuvel wrote:
>
>
>
>
>
> > On Nov 11, 11:37 am, DTL <didier.mora... at gmail.com> wrote:
> > :
> >> 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
> > :
> >> Didier
>
> > Salut Didier! Comment ca va?
>
> > So many ways to solve this.
> > Two major details to decide on first though
> > - What is the cutoff YEAR for a recorded birthday to be in the 1900s
> > or 2000s ?
> > - Is the decision to be taken for 'today', or for a particular date
> > this year?
>
> > In the solution below I just pretended all recorded dates are in the
> > 1900's allowing for folks to be more than 100 years old. If the you
> > have reason to believe that no person can be more than for example 90
> > years today, then you may want to subtract 100 if you find an age >
> > 90.
> > That will 'fix' folks born between 2000 and now.
>
> > The solution below uses TODAY as test date.
> > Use 10000*f$cvtim(,,"YEAR") if any time this years is good.
>
> > If you re-arrange the segments in 19YYMMDD format then you can just
> > subtract them from the current or sample date and then divide by 10000
> > than you will get an accurate number of years.
>
> > The plain subtraction does of course NOT render an accurate number of
> > days.
> > For example 20090101 - 20071231 is 367 days, not 18870 days but both
> > turn to 1 year which is correct because only 20070101 would be 2
> > years.
>
> > In an example procedure that gives:
>
> > $ slash = "/"
> > $ cutoff = 60
> > $loop:
> > $ READ /END=done/PROMPT="JJ/MM/AA: " SYS$COMMAND jjmmaa
> > $ yy = F$ELEM(2, slash, jjmmaa)
> > $ IF yy .EQS. slash THEN GOTO loop
> > $
> > $ yymmdd = 10000*(1900+yy) + 100*F$ELEM(1,slash,jjmmaa) + F$ELEM
> > (0,slash,jjmmaa)
> > $ now = F$CVTIME(,,"DATE") - "-" - "-"
> > $ target = cutoff - ('now' - 'yymmdd') / 10000 ! Sloppy math is good
> > enough for this work
> > $ IF target .GT. 0 THEN target = 1
> > $ write sys$output f$fao ("person is !0UL!0%Cexactly!1%Cless than!
> > %Emore than!%F !UL",target,cutoff)
> > $ GOTO loop
> > $done:
> > $ EXIT
>
> > $ @tmp ! Run on 11/11/09 :-)
> > JJ/MM/AA: 11/11/49
> > person is exactly 60
> > JJ/MM/AA: 10/11/49
> > person is exactly 60
> > JJ/MM/AA: 12/11/49
> > person is less than 60
> > JJ/MM/AA: 12/11/48
> > person is exactly 60
> > JJ/MM/AA: 12/11/47
> > person is more than 60
>
> > I'm sure you can take is from there!
>
> > btw... Mike, straight date subtraction as with F$DELTA_TIME is not too
> > useful as if requires knowing about leap years.
>
> > Cheers,
> > Hein
>
> On V7.3-2
> $
> $ start = "28-Feb-2008 0:0:0"
> $ end = "1-mar-2008 0:0:0"
> $ dif = f$delta_time( start,end )
> $ sho sym dif
> DIF = " 2 00:00:00.00"
> $
> ... so the lexical seems to cope with leap years (perhaps not with leap seconds)
Yes, of course it does.
But once you have the number of days the script would need to know
whether 366 days is 1 year or 1 year plus 1 day, making the person
potentially a year older.
Hein.
More information about the Info-vax
mailing list