Hello. On Wed 2002-12-25 at 11:47:22 +0200, [EMAIL PROTECTED] wrote: > Hi all, > > I gave the following command in the default MySQL client: > > select from_days(365); > > The result is 0000-00-00 instead of 0001-00-00. > > If I gave the following command: > > select from_days(366); > > It gives the result 0001-01-01. > > If I give numbers less than 356, the result is 0 for the year, the month, > and the day. > > Something's wrong I guess.
Yes, you use FROM_DAYS() for unsupported values. The manual explains that it is not intended for dates before 1582. http://www.mysql.com/doc/en/Date_and_time_functions.html Additionally, it returns a DATE value, for which such low values are not supported, either, but only for 1000-01-01 and later. http://www.mysql.com/doc/en/DATETIME.html So the result for the value you tried is undefined, even if it looks sometimes as if you get some reasonable result. And even if the result for an unsupported value indeed would be correct, you are not guaranteed that a new MySQL version will return the same, because it is explicitly undefined and therefore considered an implementation specific "random" value. The latter page also explains why you get no error message, if this is what you wondered about: The MySQL server only performs basic checking on the validity of a date [...]. Please note that this still allows you to store invalid dates such as 2002-04-31. It allows web applications to store data from a form without further checking. To ensure a date is valid, perform a check in your application. It also suggests that you should get 0000-00-00 for all years before 1000, which is obviously not the case. That is a minor documention glitch (see above, you should not rely on MySQL to validate ranges). HTH, Benjamin. -- [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php