php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67080 Failed to parse time string (13/04/2014)
Submitted: 2014-04-15 16:40 UTC Modified: 2014-04-15 16:59 UTC
From: jarcodallo at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.27 OS: Linux / Windows
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: jarcodallo at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-15 16:40 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-15 16:59 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-04-15 16:59 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 00:00:02 2026 UTC