php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51081 date("g:ia",strtotime("24:00")) returns 1:00am
Submitted: 2010-02-18 13:47 UTC Modified: 2010-02-18 14:26 UTC
From: mike dot turpin at gmail dot com Assigned: degeberg (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.12 OS: Windows Vista
Private report: No CVE-ID: None
 [2010-02-18 13:47 UTC] mike dot turpin at gmail dot com
Description:
------------
I suspect that this is a documentation problem in strtotime rather than a bug, but I think it should be pointed out in the doc as it's easy to fall into the trap.

strtotime("24:00") returns false

If you then have:

  date("g:ia",strtotime("24:00"))

You will get 1:00am but might be expecting 12:00am




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-18 14:02 UTC] degeberg@php.net
-Bug Type: Documentation problem
+Bug Type: Date/time related

Seems to be a bug in the 5.2 branch. Reclassifying.

====================
daniel@daniel-laptop:~$ php -r 'echo phpversion().PHP_EOL.date("g:ia",strtotime("24:00")).PHP_EOL;'
5.3.1
12:00am

daniel@daniel-laptop:~$ ~/src/php-5.2.12/sapi/cli/php -r 'echo phpversion().PHP_EOL.date("g:ia",strtotime("24:00")).PHP_EOL;'
5.2.12
1:00am
====================
 [2010-02-18 14:14 UTC] derick@php.net
-Status: Open
+Status: Bogus

This is not a bug, the following happens in 5.2:

strtotime( "24:00" ) returns "false" (because 24:00 is not supported)
date() uses an integer representation of false (0) and then formats it using the current timezone:

php -r 'echo date(DateTime::ISO8601 . " e", 0), "\n";'
1970-01-01T01:00:00+0100 Europe/London
(Yes, on Jan 1st 1970, London had an offset of UTC+1, search for "British Standard Time Act 1968 (1968 c. 45)" at http://www.srcf.ucam.org/~jsm28/british-time/)


In PHP 5,3, "24:00" is supported and the following happens:

derick@kossu:~$ php -r 'echo strtotime("24:00");'
1266537600

derick@kossu:~$ php -r 'echo date(DateTime::ISO8601 . " e", 1266537600), "\n";'
2010-02-19T00:00:00+0000 Europe/London
 [2010-02-18 14:14 UTC] mike dot turpin at gmail dot com
-Status: Bogus
+Status: Open

Just to point out that I actually found this in version 5.2.11 but don't want to upgrade yet as my web host uses this version.
 [2010-02-18 14:16 UTC] mike dot turpin at gmail dot com
I did originally point out the problem as a suspected documentation bug. Could the documentation point out this?
 [2010-02-18 14:25 UTC] svn@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=295237
Log: Fixed bug #51081. Documented that '24:00' is unsupported prior to 5.3.0.
 [2010-02-18 14:26 UTC] degeberg@php.net
-Status: Assigned
+Status: Closed

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of degeberg
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=5158fde6aa84633c6faf26e32fd82adb54e549f2
Log: Fixed bug #51081. Documented that '24:00' is unsupported prior to 5.3.0.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Sep 12 08:00:01 2025 UTC