Re: LEAP YEAR PROBLEM
Posted in 1996
> > We have run into either a bug or some bad programming. A program we've > usedfor some time suddenly started giving datetime conversion errors > (1267) today,February 29. Here is the offending code segment: > > function date_test() > > define > one_year date, > three_year date, > five_year date > > let one_year = current - 1 units year WHOOPEE!! I've been waiting for this one! Current is a datatime variable with year to second range. You cannot do arithmetic with this and a datetime variable of year to year range. That will give you the error. Bsaically the result of the rhs of the equation is 29th feb 1995 - which does not exist. > let three_year = current - 3 units year > let five_year = current - 5 units year > > ( rest of function ) Nor does 29th feb 1993 or 29th feb 1991 > > Each of the let statements generated the -1267 error. I'm guessing it > isbecause there is no February 29th in any of the earlier years. Fixing > theproblem was pretty easy. I did the following: > > let one_year = today - 365 > let three_year = today - (365 * 3) > let five_year = today - (365 * 5) > This solution is incorrect as well. the five_year figure will be one day out - there was a leap year in 1992. About the only thing you can do is to convert TODAY to YEAR, MONTH, and DAY components. You can then re-adjust year by doing the calculation, and then recreate the date, remembering that you cannot have feb 29 in non-leap years. It doesn't matter whether you use DATE or DATETIME the effect will still be the same. > Has anyone else hit this today? Is it a bug, or just bad programming? My watch didn't like the new date!! But then what dis I really expect - despite the salesman's patter! > Ididn't write it, BTW, so criticism won't bother me. > > Thanks, > Tom Allred > tom@systems.rwbost.com Malcolm Weallans Online Database Consultancy Phone 01628-72154 Fax 01628-37463 CIX - onlinedbc