php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74249 Instance created using "first day of ..." locks the day
Submitted: 2017-03-15 09:35 UTC Modified: 2017-03-15 13:23 UTC
From: peehaa@php.net Assigned:
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-03-15 09:35 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-15 10:00 UTC] requinix@php.net
Note I reopened bug #63863 earlier for this same issue.
 [2017-03-15 13:23 UTC] peehaa@php.net
-Status: Open +Status: Duplicate
 [2017-03-15 13:23 UTC] peehaa@php.net
CLosing as dupe of https://bugs.php.net/bug.php?id=63863
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC