From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,47b877165af3dad0 X-Google-Attributes: gidf7344,public X-Google-Thread: ffc31,47b877165af3dad0 X-Google-Attributes: gidffc31,public X-Google-Thread: fdd80,47b877165af3dad0 X-Google-Attributes: gidfdd80,public X-Google-Thread: 1164f8,47b877165af3dad0 X-Google-Attributes: gid1164f8,public From: "Rob Brown" Subject: Re: Y2K Conversion of Date to Internal Format Date: 1998/08/19 Message-ID: <01bdcb38$5fecbf40$2e0f4018@fsys.wave.shaw.ca>#1/1 X-Deja-AN: 382559826 References: <35D8AD45.458E8C95@idirect.com> <01bdcac2$35061860$7df84018@fsys.wave.shaw.ca> Organization: Home NNTP-Posting-Date: Tue, 18 Aug 1998 23:42:52 PDT Newsgroups: vmsnet.pdp-11,alt.sys.pdp11,comp.os.vms,comp.sys.dec I'm sure Jerome has solved this by now, but ... Rob Brown wrote in article <01bdcac2$35061860$7df84018@fsys.wave.shaw.ca>... > > > Jerome Fine 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