|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-02-29 14:01 UTC] stefan at forward dot cat
Description:
------------
See test script, DateTime::createFromFormat("Y-m", "2015-02") creates a date in march (March 1 2015) when run today 29/2/2016.
possibly related: https://bugs.php.net/bug.php?id=70956&edit=2
Test script:
---------------
<?php
$timezone = new DateTimeZone("UTC");
$result = DateTime::createFromFormat("Y-m", "2015-02", $timezone);
$timestamp = $result->format('U');
$date_time = date_create('@' . $timestamp);
date_timezone_set($date_time, $timezone);
echo date_format($date_time, 'Y-m-d H:i:s');
Expected result:
----------------
2015-03-01 12:21:30
Actual result:
--------------
not a date in march
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
I am having a similar issue as well. In my code if you do the following today (2016-02-29) var_dump(date('Y-m', strtotime('now -11 months'))); var_dump(date('Y-m', strtotime('now -12 months'))); The both return the same result, string(7) "2015-03" PHP 5.4.45