Bug #71690 [Com]: DateTime::createFromFormat malfunctions on a leap day

From: Date: Mon, 29 Feb 2016 17:13:34 +0000
Subject: Bug #71690 [Com]: DateTime::createFromFormat malfunctions on a leap day
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199529@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71690&edit=1 ID: 71690 Comment by: supraguy at yandex dot com Reported by: stefan at forward dot cat Summary: DateTime::createFromFormat malfunctions on a leap day Status: Open Type: Bug Package: Date/time related PHP Version: 7.0.3 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2016-02-29 17:05:43] stefan at forward dot cat This should say: Expected result: ---------------- A date in february Actual result: -------------- 2015-03-01 12:21:30 ------------------------------------------------------------------------ [2016-02-29 14:01:13] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71690&edit=1

« previous php.bugs (#199529) next »