php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41335 strtotime does not parse australian style dates correctly
Submitted: 2007-05-09 02:37 UTC Modified: 2008-01-17 21:03 UTC
From: daniel dot oconnor at gmail dot com Assigned: derick (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 5.2.2 OS: All
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daniel dot oconnor at gmail dot com
New email:
PHP Version: OS:

 

 [2007-05-09 02:37 UTC] daniel dot oconnor at gmail dot com
Description:
------------
Australians tend to do dates in dd/mm/yyyy format, rather than mm/dd/yyyy

strtotime cannot handle this when the seperator is a '/', but can for '-' and '.'

PHP should either:
 * Use consistent parsing all the way through. It should not matter if I pick a '-', '/' or '.'
 * Provide me an argument or configuration setting with which I can change the default behaviour.
   See http://en.wikipedia.org/wiki/Calendar_date#Date_format for a list of countries which use dd/mm/yyyy as a default, compared to a list of those who use mm/dd/yyyy.


Reproduce code:
---------------
<?php
print phpversion() . "\n\n";

$times = array();
$times[] = '1-10-2007';
$times[] = '1/10/2007';
$times[] = '1.10.2007';

$times[] = '13-10-2007';
$times[] = '13/10/2007';
$times[] = '13.10.2007';

$times[] = '2007-10-10';
$times[] = '2007/10/10';
$times[] = '2007.10.10';

$times[] = '13-13-2007';
$times[] = '13/13/2007';
$times[] = '13.13.2007';

foreach ($times as $time) {
    print $time ."\n\t" . strtotime($time) . "\n\t" . date('Y-m-d H:i:sa', strtotime($time)) . "\n\n";
}

Expected result:
----------------
---------- php ----------
5.2.2

1-10-2007
	1191196800
	2007-10-01 00:00:00am

1/10/2007
	1168387200
	2007-01-10 00:00:00am

1.10.2007
	1191196800
	2007-10-01 00:00:00am

13-10-2007
	1192233600
	2007-10-13 00:00:00am

13/10/2007
	1192233600
	2007-10-13 00:00:00am

13.10.2007
	1192233600
	2007-10-13 00:00:00am

2007-10-10
	1191974400
	2007-10-10 00:00:00am

2007/10/10
	1191974400
	2007-10-10 00:00:00am

2007.10.10
	
	1970-01-01 00:00:00am

13-13-2007
	
	1970-01-01 00:00:00am

13/13/2007
	
	1970-01-01 00:00:00am

13.13.2007
	
	1970-01-01 00:00:00am


Output completed (0 sec consumed) - Normal Termination

Actual result:
--------------
---------- php ----------
5.2.2

1-10-2007
	1191196800
	2007-10-01 00:00:00am

1/10/2007
	1168387200
	2007-01-10 00:00:00am

1.10.2007
	1191196800
	2007-10-01 00:00:00am

13-10-2007
	1192233600
	2007-10-13 00:00:00am

13/10/2007
	
	1970-01-01 00:00:00am

13.10.2007
	1192233600
	2007-10-13 00:00:00am

2007-10-10
	1191974400
	2007-10-10 00:00:00am

2007/10/10
	1191974400
	2007-10-10 00:00:00am

2007.10.10
	
	1970-01-01 00:00:00am

13-13-2007
	
	1970-01-01 00:00:00am

13/13/2007
	
	1970-01-01 00:00:00am

13.13.2007
	
	1970-01-01 00:00:00am


Output completed (0 sec consumed) - Normal Termination

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-09 06:15 UTC] derick@php.net
Using / here is problematic as it's also the separator in use by the US folks, but then in the opposite way. Providing a configuration parameter won't work as the parser would not be able to handle that. As it's deliberately not working it is not a bug, but a feature request. It would be possible to allow parsing according to a given format but that would be totally new functionality which could make it into PHP 6.
 [2008-01-17 21:03 UTC] derick@php.net
This bug has been fixed in CVS.

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

THis is now fixed (for PHP 5.3 and higher). With the date_create_from_format() function you can now do this:

<?php
$date = date_create_from_format("d/m/Y", "1/10/2007");
echo $date->format( 'c' );
?>

// outputs:
2007-10-01T22:02:37+02:00
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 01:01:35 2025 UTC