Req #42698 [Opn->Nab]: date parsing in DateTime / date_parse - accept optional format

From: Date: Sat, 25 Jan 2014 14:29:11 +0000
Subject: Req #42698 [Opn->Nab]: date parsing in DateTime / date_parse - accept optional format
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184002@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=42698&edit=1 ID: 42698 Updated by: derick@php.net Reported by: david at palepurple dot co dot uk Summary: date parsing in DateTime / date_parse - accept optional format -Status: Open +Status: Not a bug Type: Feature/Change Request Package: Date/time related Operating System: Linux PHP Version: 5.2.4 Block user comment: N Private report: N New Comment: 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 http://www.php.net/downloads.php 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 http://uk1.php.net/datetime.createfromformat and http://uk1.php.net/manual/en/function.date-parse-from-format.php Previous Comments: ------------------------------------------------------------------------ [2007-10-31 17:27:43] 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) ------------------------------------------------------------------------ [2007-09-18 08:52:32] david at palepurple dot co dot uk Description: ------------ 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: --------------- <?php $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: ---------------- 1601/12/30. If both formats are the same, then the output should match the input. Actual result: -------------- n/a. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=42698&edit=1

« previous php.bugs (#184002) next »