|
Posted by Gordon Burditt on 04/21/06 21:01
>Hello. I noticed a strange thing while using strtotime() and date()
>functions in combination to generate from MySQL into a readable format.
>
>By default, the MySQL date field will be 0000-00-00 00:00:00 When I
>pass this to strtotime() to generate the timestamp, and then pass it to
>the date function, it generates 30-11-1999.
Generally, I prefer to avoid the PHP date functions as much as
possible, except maybe when it's dealing with the current date, in
favor of the MySQL date/time functions. Why? The PHP functions
don't have enough range to cover the life expectancy of a living
person. That's pretty constraining.
>[snippet]
><?
>print ( "<br> strtotime for '0000-00-00 00:00:00' : " . strtotime (
>'0000-00-00 00:00:00' ) );
>print ( "<br> date for the above : " . date ( "d-m-Y", strtotime (
>'0000-00-00 00:00:00' ) ) );
>?>
>[/snippet]
>
>I am on PHP 5.0.2
>Why this unusual behaviour? Or is it an expected behaviour?
The allowed range for *PHP* timestamps is the same range as UNIX
timestamps. This may vary from system to system depending on whether
a time_t is considered signed (1901 - 2038) or unsigned (1970 -
2106). In any case the year 0 is way out of range. The Year 2038
problem will start to bite shortly, given the existence of 30-year
mortgages.
Gordon L. Burditt
[Back to original message]
|