php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54185 strtotime misinterprets dates in format "1 Aug, 2005" for the 2000s
Submitted: 2011-03-07 18:57 UTC Modified: 2011-03-07 19:05 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: chris at sternal-johnson dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.5 OS: Ubuntu 10.10 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris at sternal-johnson dot com
New email:
PHP Version: OS:

 

 [2011-03-07 18:57 UTC] chris at sternal-johnson dot com
Description:
------------
It appears that strtotime misinterprets dates in formats like "1 Aug, 2005" or "2 
Mar, 2008" for the 2000s. Dates in 1900s are unaffected. The month and day values 
are correctly interpreted, but the year is being set to the current instead of the 
correct value.

Test script:
---------------
strtotime('2 Mar, 2008');<br />
<?php print strtotime('2 Mar, 2008')?><br />
<br />
strtotime('2 Mar 2008');<br />
<?php print strtotime('2 Mar 2008')?><br />
<br />
strtotime('2 Mar, 1999');<br />
<?php print strtotime('2 Mar, 1999')?><br />
<br />
strtotime('2 Mar 1999');<br />
<?php print strtotime('2 Mar 1999')?><br />

Expected result:
----------------
strtotime should generate the same date for '2 Mar, 2008' as '2 Mar 2008'.

Actual result:
--------------
strtotime wrongly generates 1299114480 (2 Mar 2011) for '2 Mar, 2008' but 
correctly interprets 1204434000 for '2 Mar 2008'.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-07 19:05 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-03-07 19:05 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is a tricky one, but not a bug.

2 Mar, 2008 is interpreted as "March 2nd, 20:08".
1999 is not a valid time, and as a fallback it will then be used as a year:

derick@whisky:~$ pe 5.3dev
derick@whisky:~$ php -r 'print_r(date_parse("2 Mar, 2008"));'
Array
(
    [year] => 
    [month] => 3
    [day] => 2
    [hour] => 20
    [minute] => 8
    [second] => 0
    [fraction] => 
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 0
    [errors] => Array
        (
        )

    [is_localtime] => 
)
derick@whisky:~$ php -r 'print_r(date_parse("2 Mar, 1999"));'
Array
(
    [year] => 1999
    [month] => 3
    [day] => 2
    [hour] => 
    [minute] => 
    [second] => 
    [fraction] => 
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 0
    [errors] => Array
        (
        )

    [is_localtime] => 
)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 02:01:33 2024 UTC