php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68161 DateTime->modify "first day of this month"
Submitted: 2014-10-05 23:13 UTC Modified: 2016-11-11 11:41 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: thunberg at gmail dot com Assigned: leigh (profile)
Status: Closed Package: Date/time related
PHP Version: 5.6.1 OS: Linux 2.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thunberg at gmail dot com
New email:
PHP Version: OS:

 

 [2014-10-05 23:13 UTC] thunberg at gmail dot com
Description:
------------
Using setTimestamp after modifying a DateTime object with "first day of this month" string results in the incorrect date and time.

If "first day of this month" is replaced with something else like "tomorrow" it works fine. For some reason the example below appears to lock in the date component, but not the time.

Test script:
---------------
$time_start = new DateTime('2014-10-02');

echo $time_start->format('r') . "\n";

$time_start->modify('first day of this month');

echo $time_start->format('r') . "\n";

$time_start->setTimestamp(time());

echo $time_start->format('r') . "\n";

Expected result:
----------------
Current date and time

Actual result:
--------------
October 1st

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-08 04:16 UTC] leigh@php.net
-Status: Open +Status: Verified
 [2014-10-08 04:16 UTC] leigh@php.net
Verified in 5.4, 5.5, 5.6 and master.

The documentation for setTimestamp() clearly states: "Sets the date and time based on an Unix timestamp", however the date portion is not set in this case.
 [2014-10-08 05:31 UTC] leigh@php.net
-Status: Verified +Status: Analyzed -Assigned To: +Assigned To: leigh
 [2014-10-08 05:31 UTC] leigh@php.net
Patch submitted: https://github.com/php/php-src/pull/870
 [2016-11-11 11:41 UTC] derick@php.net
-Status: Analyzed +Status: Closed
 [2016-11-11 11:41 UTC] derick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

This seems to work fine in PHP 5.6.27. It seems to have been fixed in 5.6.19 and 7.0.4: https://3v4l.org/S3iS8
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 01:01:30 2024 UTC