|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-07-04 00:20 UTC] kaido at tradenet dot ee
Description:
------------
When creating DateTime object from string and using z (day of year) format option,
the 29.02 of the leap year is missing. works ok in 5.3.5
Test script:
---------------
for ($d=55;$d<65;$d++) {
$dt = DateTime::createFromFormat ('z.Y', $d.'.2012');
$dd = $dt->format ('d.m.Y');
echo "$d $dd\n";
}
29.02.2012 is clearly missing ..
Expected result:
----------------
55 25.02.2012
56 26.02.2012
57 27.02.2012
58 28.02.2012
59 29.02.2012
60 01.03.2012
61 02.03.2012
62 03.03.2012
63 04.03.2012
64 05.03.2012
Actual result:
--------------
55 25.02.2012
56 26.02.2012
57 27.02.2012
58 28.02.2012
59 01.03.2012
60 02.03.2012
61 03.03.2012
62 04.03.2012
63 05.03.2012
64 06.03.2012
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 14:00:01 2025 UTC |
Possible workaround: $ php -r 'echo DateTime::createFromFormat("z Y", "59 2016")->format("Y-m-d"), PHP_EOL;' 2016-03-01 $ php -r 'echo DateTime::createFromFormat("Y z", "2016 59")->format("Y-m-d"), PHP_EOL;' 2016-02-29 $ php -v PHP 5.4.31-1+deb.sury.org~precise+1 (cli) (built: Jul 25 2014 07:04:32) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.2, Copyright (c) 1999-2013, by Zend Technologies If it can be any helpful in Google searches for this bug, we encountered this when using MongoDB $dayOfYear aggregation option.As of PHP 8.0.10, it is no longer possible to use "z.Y" at all ("A 'day of year' can only come after a year has been found"). Fixing the unsupported format to "Y.z" brings the desired results[1]. So this is a documentation problem. [1] <https://3v4l.org/2In8R>