From: "Rob Brown" <robbrown@shaw.wave.ca>
Subject: Re: Y2K Conversion of Date to Internal Format
Date: 1998/08/19 [thread overview]
Message-ID: <01bdcb38$5fecbf40$2e0f4018@fsys.wave.shaw.ca> (raw)
In-Reply-To: 01bdcac2$35061860$7df84018@fsys.wave.shaw.ca
I'm sure Jerome has solved this by now, but ...
Rob Brown <robbrown@shaw.wave.ca> wrote in article
<01bdcac2$35061860$7df84018@fsys.wave.shaw.ca>...
>
>
> Jerome Fine <jhfine@idirect.com> wrote in article
> <35D8AD45.458E8C95@idirect.com>...
> > DATE = CONVRT ( MONTH, DAY, YEAR )
> > MONTH = MONTH - 2
> > IF ( MONTH .LE. 0 ) MONTH = MONTH + 12; YEAR = YEAR - 1
> > Q = YEAR / 100
> > R = YEAR - Q * 100
> > DATE = ( YEAR - 1910 ) * 365 + Q / 4 + R / 4 +
> > ( MONTH + 1 ) * 28 + ( 26 *
> > MONTH - 2 ) / 10
> The problem obviously has something to do with the 1999 ->
> 2000 transition, but I can't see what it is right now.
As Kelvin Smith observed in another article, the problem is that when
the year changes from 1999 to 2000, the Q/4 term contributes one more
day, but the R/4 term contributes 24 less.
The solution is to get rid of Q and R and just use a term containing
YEAR/4. You don't need to worry about the fact that 2100 is not a leap
year. Jerome stated he was using 16 bit integer arithmetic, which
overflows May 31, 2089.
So the corrected algorithm is:
MONTH = MONTH - 2
IF (MONTH .LE. 0) THEN
MONTH = MONTH + 12
YEAR = YEAR - 1
ENDIF
DATE = (YEAR-1910)*365 ! 365 days per year
+ (YEAR-1910+2)/4 ! leap day every four years
+ (MONTH+1)*28 ! amazing days per month calculation
+ (26*MONTH-2)/10
+ DAY
+ 6 ! magic number to make it all
! come out right,
! but coincidentally the number of days
! from Dec 26 to Jan 1.
You're welcome.
- Rob
--
Rob Brown | RSX
G. Michaels Consulting Ltd. | VMS
brown@gmcl.com | Y2K
next prev parent reply other threads:[~1998-08-19 4:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-17 4:00 Y2K Conversion of Date to Internal Format Jerome Fine
1998-08-19 4:00 ` Rob Brown
1998-08-19 4:00 ` Rob Brown [this message]
1998-08-19 4:00 ` Jerome Fine
1998-08-20 4:00 ` Pierre.Bru
[not found] ` <199808201251.HAA30561@x8.dejanews.com>
1998-08-21 4:00 ` Jerome Fine
1998-08-21 4:00 ` D.Webb
1998-08-22 4:00 ` Brian Inglis
1998-08-23 4:00 ` Charles Richmond
1998-08-24 4:00 ` Martin Vorlaender
1998-08-24 4:00 ` Pierre.Bru
-- strict thread matches above, loose matches on Subject: below --
1998-08-15 4:00 Jerome Fine
1998-08-17 4:00 ` Jim Becker
1998-08-17 4:00 ` Kevin Handy
1998-08-20 4:00 ` George Cornelius
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox