php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66825 DateTime::createFromFormat not work as documentation example and more cases
Submitted: 2014-03-05 13:28 UTC Modified: 2014-03-05 16:05 UTC
From: nadavvin at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.25 OS: windows, linux
Private report: No CVE-ID: None
 [2014-03-05 13:28 UTC] nadavvin at gmail dot com
Description:
------------
problems with DateTime::createFromFormat:

1) example create the date in 1970 instead of 2009
2) failed to create date object from my trying to do format: 'Y-m-d?H:i:sP'


Test script:
---------------
<?php

//example #2 from http://il1.php.net/manual/en/datetime.createfromformat.php

$format = 'Y-m-!d H:i:s';
$date = DateTime::createFromFormat($format, '2009-02-15 15:16:17');
echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";


//my trying to create from DateTime::RFC3339 format


$dt = new DateTime(null,new DateTimeZone('gmt'));
//$time = $dt->format(DateTime::RFC3339);
$time = $dt->format('Y-m-d\TH:i:sP');
echo $time."\n";

$dt = DateTime::createFromFormat($time, 'Y-m-d?H:i:sP');
//$dt = DateTime::createFromFormat($time, DateTime::RFC3339);

var_dump($dt);

Expected result:
----------------
1) Format: Y-m-!d H:i:s; 2009-02-15 15:16:17
2) not false in var_dump($dt);

Actual result:
--------------
1) Format: Y-m-!d H:i:s; 1970-01-15 15:16:17
2) DateTime object dump

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-05 16:05 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2014-03-05 16:05 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You have the ! in your format (before the "d"), which is documented at the URL you're pointed to as:

! 	Resets all fields (year, month, day, hour, minute, second, fraction and timzone information) to the Unix Epoch
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 14:01:31 2024 UTC