Re: DATE and UNITS problem
Posted in 1995
another approach would be: # get the first of the month for a given date function first_of_month(i_date) #_inputs define i_date date #_outputs define o_date date let o_date = MDY(MONTH(i_date),01,YEAR(i_date)) return o_date end function # get the last of the month for a given date function last_of_month(i_date) #_inputs define i_date date #_outputs define o_date date if(MONTH(i_date)!=12) then let o_date = MDY(MONTH(i_date)+1,01,YEAR(i_date)) - 1 UNITS DAY else let o_date = MDY(01,01,YEAR(i_date)+1) - 1 UNITS DAY end if return o_date end function } } 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 } } -- regards, +----------------------------------------------------------------------------+ | . . | Bob Baskett | | ... ... | Software Engineer | | ..... ..... | Business Systems Integration Group | | .. ... .. | Semiconductor Products Sector | | . . . | Mesa, AZ | | | President, Informix Users Group Of Arizona | | Motorola, Inc. | | +----------------------------------------------------------------------------+ | Sun 690MP 4.1.3, Online 5.01, 4.10.UD1 Tools, Fourgen v4.10.UC1 | +----------------------------------------------------------------------------+