php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61314 Cannot mix European and 2 digit year
Submitted: 2012-03-07 09:14 UTC Modified: 2015-09-01 23:55 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: mwwaygoo at hotmail dot com Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.10 OS: Ubuntu 11.10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mwwaygoo at hotmail dot com
New email:
PHP Version: OS:

 

 [2012-03-07 09:14 UTC] mwwaygoo at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.strtotime
---

Specifying a date of 10-11-77 will epoch, and not create the timestamp for 10-11-1977 as expected, according to the two notes on the strtotime() function page shown below.
This should really say "whereas if the separator is a dot (.), then the European d.m.y format is assumed"

    Note:

    If the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999.


    Note:

    ...whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.


Test script:
---------------
echo date("Y-m-d H:i:s", strtotime("10-11-77 03:12:01")); // unexpected fail: supposed to be d/m/y with year 77 auto changed to 1977
echo date("Y-m-d H:i:s", strtotime("10.11.77 03:12:01")); // pass: EUR d/m/y with year 77 auto changed to 1977
echo date("Y-m-d H:i:s", strtotime("10/11/77 03:12:01")); // pass: US m/d/y
echo date("Y-m-d H:i:s", strtotime("77-11-10 03:12:01")); // pass: ISO 8601 y-m-d
echo date("Y-m-d H:i:s", strtotime("77/11/10 03:12:01")); // expected fail: US m/d/y data incorrect


Expected result:
----------------
1977-11-10 03:12:01
1977-11-10 03:12:01
1977-10-11 03:12:01
1977-11-10 03:12:01
1970-01-01 00:00:00

Actual result:
--------------
1970-01-01 00:00:00
1977-11-10 03:12:01
1977-10-11 03:12:01
1977-11-10 03:12:01
1970-01-01 00:00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-07 09:21 UTC] aharvey@php.net
-Package: PHP options/info functions +Package: Date/time related
 [2015-08-31 18:21 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2015-08-31 18:21 UTC] cmb@php.net
> Specifying a date of 10-11-77 will epoch, […]

No, strtotime() will fail for such a "date", and return FALSE as
documented.

> This should really say "whereas if the separator is a dot (.),
> then the European d.m.y format is assumed".

I agree, that some clarification in the manual is in order.
 [2015-09-01 23:52 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=337698
Log: clarified behavior of nn-nn-nn parsing (fixes #61314)
 [2015-09-01 23:55 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2015-09-01 23:55 UTC] cmb@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC