Re: Trouble with date compuation
Posted in 1995
pigi@frumar.it writes: -> ->Hi, -> I have a little problem with date computation. ->The problem is how informix handle this field. I mean -> I have a function like this: -> function name() -> define a date, -> b date -> -> let a = today -> let b = today -3 units month -> return a,b -> end function -> ->It works correctly if the monts is less or equal 30 day (February,April, June ecc.. ) -> but if the month is of 31 days I receive , at the 2nd let instruction, -> ->a FORM STATEMENT ERROR -1267 -> The RESULT OF A DATETIME COMPUTATION IS OUT OF RANGE. This is actually correct behavior. Anytime adding or subtracting months to or from a date will result in a date which does not exist, an error will occur. The reason for this is that Informix did not think it was appropriate to make assumptions about what we really meant. Does 1/31/95 + 1 month equal: (a) February 28, 1995 (b) March 1, 1995 (c) March 2, 1995 (d) March 3, 1995 (e) none of the above (f) all of the above Which to me means month math is almost completely useless. I (and many other people) have just resorted to writing our own functions to get around this problem. One of the most popular methods of getting the last day of the month is to subtract 1 day from the first day of the following month. Or if it suits your purpose you can assume there are always 30 days in a month, so instead of adding/subtracting 3 months, add or subtract 90 days instead. At any rate, I don't recall if it were ever made into an official feature request, but the suggestion was made to have a default behavior as the current behavior, but have an environment variable which if set to various values would allow for variations on how month math would be applied. ->P.s. Sorry for my not good english. Your English is much better than my Italian! Regards, - Cathy -------------------------------------------------------------------------------- Cathy Kipp e-mail: ckipp@vth1.vth.colostate.edu Phone: (970) 491-1294 Colorado State University Veterinary Teaching Hospital Fax: (970) 491-1205