5

Php strtotime('0000-00-00 00:00') showing strange behavior. Its returning negative value something like -62169984000.

I have Php version 5.4.17 in my 64-bit System. It should return false value which is expected.

But when I checked in other 32-bit system its returning false.

Mark
  • 8,046
  • 15
  • 48
  • 78
pankaj
  • 43
  • 1
  • 11

1 Answers1

11

On your system integers are 64 bits, so there is enough range to count seconds from the Unix epoch all the way back to 0 AD. Therefore strtotime works as advertised and returns a (very large) negative number. The return value is correct, your expectation is not.

In a 32-bit system the integer range is only sufficient to cover a ~68 year period, so going back earlier than about 1970 - 68 = 1902 will result in false being returned. Dates between 1902 and 1970 will still result in negative numbers.

Jon
  • 428,835
  • 81
  • 738
  • 806
  • But I Just checked in a 64 bit system with php 5.2 version its returning false. – pankaj Jul 23 '13 at 09:11
  • @pankaj: What's the value of `PHP_INT_SIZE` on that system? If it's 4 then it only has 32-bit integers. In any case, PHP 5.2 is quite old and it may behave differently -- I wouldn't know. – Jon Jul 23 '13 at 09:12
  • It's debatable though whether *"Midnight of Nulluary(?) Zero of the year Zero"* should be a valid date and return a timestamp... Maybe the calendar of that era worked differently? :) – deceze Jul 23 '13 at 09:18
  • @deceze: When date parts are zero they are treated as -1 and the date is adjusted backwards automatically. That's certainly not what I want my programming language to do, but it's standard PHP behavior. – Jon Jul 23 '13 at 09:23
  • @Jon I checked in 2 different 64 bit system. the value of PHP_INT_SIZE is 8 in both. But in one system its showing negative value and in another it returning false. Its totally strange behavior. – pankaj Jul 23 '13 at 09:31
  • @pankaj: I totally agree with that. That's the "PHP tax" on developers. :/ – Jon Jul 23 '13 at 09:33