Re: DATE and UNITS problem
Posted in 1995
} Date: Thu, 23 Feb 95 10:28:38 MST } From: tomj@farside.cfer.com (Thomas Jacobsen) } To: informix-list@rmy.emory.edu } Subject: Re: DATE and UNITS problem } } Cathy Kipp writes: } [snip] } } Well, it's not a bug, it's a feature. The problem is that there are several } } potentially correct answers to Jan 31, 1995 + 1 month: } } } } a) February 28, 1995 (matching end of month) } } b) March 3, 1995 (31 days) } } c) March 2, 1995 (someone who wants a 30 day month) } } c) Other (use your imagination) } } } } Informix has decided that they don't want to decide for the user what is } } correct, so they choose to have the program error out instead. The work } } around is to write your own routine for month addition/subtraction in } } order to take all the exceptions into account and return the answers you } } prefer. Thomas Jacobsen writes: } } You can argue forever about whether it's a bug or a feature. I'd say it's } a bug because the language specifically allows you to add units of months to } a date variable; therefore it should have built-in rules for handling that } addition. I would suggest that the problem is in the documentation, not in the action of the Informix software. Cathy makes the point (and others have made it as well) that what "plus one month" means near the end of the month is hard to define. By using WHENEVER ANY ERROR, a programmer can trap for -1267 errors and handle end-of-month in the locally defined manner, while allowing normal date math to handle the beginning and middle of the month. The problem is that the documentation does not emphasize this approach. } Here's a related problem which is a bug. It works with the 4.10 UC1 runner, } but bombs with the -1267 datetime computation out of range error on the } 4.12 UE1 runner: } } main } DEFINE } current_month,prev3_month DATETIME MONTH TO MONTH, } month_char char(2) } } LET current_month= "02" } display "current month = ", current_month } LET prev3_month=current_month - 3 UNITS MONTH } let month_char = prev3_month } display "prev3_month = ",month_char } end main } } In other words, previously, the month calculation allowed wrapping around } the year, but apparently not in 4.12. } ============================================================== } Thomas Jacobsen, IS Development e-mail: tomj@cfer.com I agree. This is a bug. February minus three months should indeed be December. ESPECIALLY since it used to work and no longer does. Regards, Alan +---------------------------+-----------------------------------------------+ | R. Alan Popiel | Internet: alan@den.mmc.com | | Martin Marietta, SLS | Voice: 303-977-9998 | | P.O. Box 179, M/S 3810 | Standard disclaimers apply. Cutesy ones, too. | | Denver, CO 80201-0179 USA | Your mileage may vary. Void where prohibited. | +---------------------------+-----------------------------------------------+