Bug #74249 [Opn]: Instance created using "first day of ..." locks the day

From: Date: Wed, 15 Mar 2017 10:00:06 +0000
Subject: Bug #74249 [Opn]: Instance created using "first day of ..." locks the day
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207849@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74249&edit=1 ID: 74249 Updated by: requinix@php.net Reported by: peehaa@php.net Summary: Instance created using "first day of ..." locks the day Status: Open Type: Bug Package: Date/time related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Note I reopened bug #63863 earlier for this same issue. Previous Comments: ------------------------------------------------------------------------ [2017-03-15 09:35:40] peehaa@php.net Description: ------------ After initializing a new DateTime object using "first day of this ..." DateTime::setDate() doesn't correctly set the day anymore. It will always result 1. $date1 = new \DateTime('first day of this month'); echo $date1->format('Y-m-d') . "\n"; // correct: 2017-03-01 $date1->setDate(2017, 1, 8); echo $date1->format('Y-m-d') . "\n"; // wrong: 2017-01-01 I tried several things like "first day of january" and "first day of this month". https://3v4l.org/I2maQ Test script: --------------- <?php $date1 = new \DateTime('first day of this month'); echo $date1->format('Y-m-d') . "\n"; $date1->setDate(2016, 1, 8); echo $date1->format('Y-m-d') . "\n"; $date2 = new \DateTime('first day of january'); echo $date2->format('Y-m-d') . "\n"; $date2->setDate(2016, 3, 8); echo $date2->format('Y-m-d') . "\n"; Expected result: ---------------- 2017-03-01 2016-01-08 2017-01-01 2016-03-08 Actual result: -------------- 2017-03-01 2016-01-01 2017-01-01 2016-03-01 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74249&edit=1

« previous php.bugs (#207849) next »