|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-03-15 10:00 UTC] requinix@php.net
[2017-03-15 13:23 UTC] peehaa@php.net
-Status: Open
+Status: Duplicate
[2017-03-15 13:23 UTC] peehaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 13:00:01 2025 UTC |
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