php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62166 createfromFormat assign current time by default when reading date only string.
Submitted: 2012-05-26 10:45 UTC Modified: 2012-07-14 23:51 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: lenzai2004-dev at yahoo dot fr Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.13 OS: Ubuntu 11.10 64bits
Private report: No CVE-ID: None
 [2012-05-26 10:45 UTC] lenzai2004-dev at yahoo dot fr
Description:
------------
DateTime:createFromFormat() and DateTime::__construct are not consistent for parsing dates.

__construct sets default time at 00:00:00
DateTime::createFromFormat() sets default time at current time

Test script:
---------------
var_export(DateTime::createFromFormat("Y-m-d","2012-05-11"));
var_export(new DateTime("2012-05-11"));


Expected result:
----------------
DateTime::__set_state(array(
   'date' => '2012-05-11 00:00:00',
   'timezone_type' => 3,
   'timezone' => 'Asia/Chongqing',
))
	DateTime::__set_state(array(
   'date' => '2012-05-11 00:00:00',
   'timezone_type' => 3,
   'timezone' => 'Asia/Chongqing',
))

Actual result:
--------------
DateTime::__set_state(array(
   'date' => '2012-05-11 18:34:45',
   'timezone_type' => 3,
   'timezone' => 'Asia/Chongqing',
))
	DateTime::__set_state(array(
   'date' => '2012-05-11 00:00:00',
   'timezone_type' => 3,
   'timezone' => 'Asia/Chongqing',
))

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-07 19:59 UTC] stas@php.net
-Status: Open +Status: Feedback
 [2012-07-07 19:59 UTC] stas@php.net
The documentation for date_create_from_format states:

! Resets all fields (year, month, day, hour, minute, second, fraction and timzone 
information) to the Unix Epoch Without !, all fields will be set to the current 
date and time.

So maybe the format should be !Y-m-d? Would that solve the issue?
 [2012-07-07 20:29 UTC] lenzai2004-dev at yahoo dot fr
-Status: Feedback +Status: Open
 [2012-07-07 20:29 UTC] lenzai2004-dev at yahoo dot fr
Thank you for your Help. Sorry for misreading documentation.
 [2012-07-14 23:51 UTC] stas@php.net
-Status: Open +Status: Not a bug
 [2012-07-14 23:51 UTC] stas@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 10:01:31 2024 UTC