|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52430 date_parse parse 24:xx:xx as valid time
Submitted: 2010-07-24 21:20 UTC Modified: 2010-08-30 18:40 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: pulzarraider at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.3 OS: Win 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: pulzarraider at gmail dot com
New email:
PHP Version: OS:


 [2010-07-24 21:20 UTC] pulzarraider at gmail dot com
In the 24-hour time notation, the day begins at midnight, 00:00, and the last minute of the day begins at 23:59.

Date_parse function returns no warning and no error when any time starting with hour "24" is used as parameter. But some error is expected, because 2010-1-1 24:59:59 is NOT valid date.

This can cause serious errors in scripts that use date_parse for validating dateTime strings.

Test script:

date_parse('2010-1-1 24:00:00');
//This is invalid date, but date_parse returns no error and warning
//Expected: error "Unexpected character"

//date_parse('2010-1-1 24:59:59'); 
//This is also invalid date, but date_parse returns no error and warning
//Expected: error "Unexpected character"


Expected result:
Array (
[year] => 2010
[month] => 1
[day] => 1
[hour] => 0
[minute] => 0
[second] => 0
[fraction] => 0
[warning_count] => 0 
[warnings] => Array ( ) 
[error_count] => 1 
[errors] => Array ([9]=>'Unexpected character')
[is_localtime] =>false

Actual result:
Array (
[year] => 2010
[month] => 1
[day] => 1
[hour] => 24                   <===== wrong
[minute] => 0
[second] => 0
[fraction] => 0
[warning_count] => 0 
[warnings] => Array ( ) 
[error_count] => 0              <===== wrong
[errors] => Array ( )           <===== wrong
[is_localtime] =>false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-26 08:00 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: derick
 [2010-07-26 08:00 UTC]
According to ISO 8601: 

"As this International Standard is based on the 24-hour timekeeping system that 
is now in common use, hours are represented by two digits from [00] to [24], 
minutes are represented by two digits from [00] to [59], and seconds are 
represented by two digits from [00] to [60]. For most purposes, times will be 
represented by four digits [hhmm].

The representation of the hour by [24] is only allowed to indicate midnight, see 

The representation of the second by [60] is only allowed to indicate the 
positive leap second or a time-point within that


Midnight will normally be represented as [0000] or [2400].


The end of one day [2400] coincides with [0000] at the start of the next day, 
e.g. 2400 on 1985 April 12 is the same as 0000 on 1985 April 13. If there is no 
association with a date or a time-interval both a) and b) represent the same 
clock time in the 24-hour timekeeping system."

So 2400 isn't technically wrong but it doesn't look like the regular expressions 
in are context specific right now (eg. 24 only if followed by 00 
so it allows 2401 through 2459). This looks like a pretty big rewrite. Assigning 
to Derick.
 [2010-07-26 11:54 UTC]
date_parse (and friends) are not made to validate. It will also happily accept "2010-02-31" as a date. Since PHP 5.3.x, date_parse() however adds a warning if a date is invalid; I should add that for time as well:

derick@kossu:/tmp$ php bug52430.php
array(12) {

  array(1) {
    string(27) "The parsed date was invalid"
 [2010-08-30 18:40 UTC]
Automatic comment from SVN on behalf of derick
Log: - Fixed bug #52430 (date_parse parse 24:xx:xx as valid time). (Derick)
 [2010-08-30 18:40 UTC]
-Status: Verified +Status: Closed
 [2010-08-30 18:40 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu May 06 17:01:26 2021 UTC