You are here: Re: unusual behaviour of strtotime() for '0000-00-00 00:00:00' input « PHP Programming Language « IT news, forums, messages
Re: unusual behaviour of strtotime() for '0000-00-00 00:00:00' input

Posted by ljb on 04/22/06 03:50

rithish@gmail.com wrote:
> Hello. I noticed a strange thing while using strtotime() and date()
> functions in combination to generate from MySQL into a readable format.
> ...
><?
> 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?

It's good to understand how things work (or not).

Consider your case: strtotime("0000-00-00 00:00:00")

The year 0000 is taken as 2000, due to Y2K handling. (Years 00-68 are
assumed to be 2000-2068 and 69-99 are 1969-1999.) Arguably, it should
be distinguishing 00 from 0000, but it doesn't.

January is month 1, so "month 0" is one month before that, December.

Similarly "day 0" is one day before the first of the month: the last day of
the previous month.

Therefore 0000-00-00 is one day before one month before 2000-01-01,
giving 1999-11-30.

So it makes sense, even if it is fundamentally wrong!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация