Re: DATE and UNITS problem
Posted in 1995
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
Cathy Kipp writes: } Alvin Koh writes: } -> } ->I have a 4gl program that uses the DATE and UNITS as in } -> } -> main } -> define d1 date } -> define d2 date } -> let d1 = "1/31/1995" } -> let d2 = d1 + 1 units month } -> display d2 } -> end main } -> } ->The program fails because it trys to assign d2 a value of "2/31/1995" which } ->is of course an invalid date and results in the following error: } } 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. } } Regards, } } - Cathy } } -------------------------------------------------------------------------------- } Cathy Kipp e-mail: ckipp@vth1.vth.colostate.edu Phone: (303) 491-1294 } Colorado State University Veterinary Teaching Hospital Fax: (303) 491-1205 } 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. 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 ConferTech International phone: 303-633-3083 12110 North Pecos Street fax: 303-633-3001 Westminster, CO 80234-2076
Related threads
- Date-field - #months : 1267: The result of a datetime computation is out of range.
- Re: Leap Year
- Is this an informix leap year bug?