|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42698 date parsing in DateTime / date_parse - accept optional format
Submitted: 2007-09-18 08:52 UTC Modified: 2014-01-25 14:29 UTC
Avg. Score:4.7 ± 0.4
Reproduced:17 of 18 (94.4%)
Same Version:12 (70.6%)
Same OS:11 (64.7%)
From: david at palepurple dot co dot uk Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.4 OS: Linux
Private report: No CVE-ID: None
 [2007-09-18 08:52 UTC] david at palepurple dot co dot uk
The default set of date/times accepted by strtotime() is limited (e.g. in not understanding English/UK date formats (dd/mm/yyyy).

It would be nice if the new DateTime object accepted a date() compatible format string to a 'date_parse' like method.

(I like the DateTime object, as it seems to handle a larger range of dates than strtotime() for me).

Reproduce code:
$dt = new DateTime();
$dt->parse('30/12/1601', 'd/m/Y');
echo $dt->format('Y/m/d'); 

(Presumably successive parse calls would overwrite the state from a previous one)

Expected result:

If both formats are the same, then the output should match the input.

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-31 17:27 UTC] oliver at realtsp dot com
this is an important feature in order to replace the functionality provided by strptime (which is of course limited to the range of 32bit timestamp).

without this feature the DateTime class cannot be used for rigorous parsing of dates according to a specified format, such as is good practice in forms validation where input of months and days can otherwise be ambiguous (eg UK vs US date formats)
 [2011-02-21 20:58 UTC]
-Summary: date parsing in DateTime / date_parse - accept optioanl format +Summary: date parsing in DateTime / date_parse - accept optional format -Package: Feature/Change Request +Package: Date/time related
 [2014-01-25 14:29 UTC]
-Status: Open +Status: Not a bug
 [2014-01-25 14:29 UTC]
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

This is already possible with date_parse_from_format and date_create_from_format. 

See and
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 06:01:23 2021 UTC