Bug #67080 [Opn->Nab]: Failed to parse time string (13/04/2014)

From: Date: Tue, 15 Apr 2014 16:59:10 +0000
Subject: Bug #67080 [Opn->Nab]: Failed to parse time string (13/04/2014)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185259@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67080&edit=1 ID: 67080 Updated by: requinix@php.net Reported by: jarcodallo at gmail dot com Summary: Failed to parse time string (13/04/2014) -Status: Open +Status: Not a bug Type: Bug Package: Date/time related Operating System: Linux / Windows PHP Version: 5.4.27 Block user comment: N Private report: N New Comment: As described in the manual, http://www.php.net/manual/en/datetime.formats.date.php and as demonstrated in your code, that format is interpreted as MM/DD/YYYY. Either use different delimiters, such as hyphens for DD-MM-YYYY, or parse the date string yourself. Previous Comments: ------------------------------------------------------------------------ [2014-04-15 16:40:51] jarcodallo at gmail dot com Description: ------------ I try convert string '13/04/2014' to DateTime Object, but this method "new DateTime('13/04/2014');", return Failed to parse time string (13/04/2014) at position 0 (1): Unexpected character. Try other dates and after this there is no problem, hope you can help me Test script: --------------- $date1 = new DateTime('12/04/2014'); var_dump($date1); $date2 = new DateTime('13/04/2014'); var_dump($date2); Expected result: ---------------- object(DateTime)[1] public 'date' => string '2014-12-04 00:00:00' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) object(DateTime)[1] public 'date' => string '2014-12-04 00:00:00' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) object(DateTime)[1] public 'date' => string '2014-13-04 00:00:00' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) object(DateTime)[1] public 'date' => string '2014-13-04 23:59:59' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) Actual result: -------------- object(DateTime)[1] public 'date' => string '2014-12-04 00:00:00' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) object(DateTime)[1] public 'date' => string '2014-12-04 00:00:00' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (13/04/2014) at position 0 (1): Unexpected character' in D:\wamp\www\tools\bug-datetime.php on line 8 Exception: DateTime::__construct(): Failed to parse time string (13/04/2014) at position 0 (1): Unexpected character in D:\wamp\www\tools\bug-datetime.php on line 8 Call Stack # Time Memory Function Location 1 0.0000 146168 {main}( ) ..\bug-datetime.php:0 2 0.0156 147456 __construct ( ) ..\bug-datetime.php:8 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67080&edit=1

« previous php.bugs (#185259) next »