|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52454 Relative dates and getTimestamp increments by one day
Submitted: 2010-07-27 11:46 UTC Modified: 2010-08-30 18:26 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ben dot davies at stickyeyes dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.3 OS: Windows 7 Professional
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
22 + 40 = ?
Subscribe to this entry?

 [2010-07-27 11:46 UTC] ben dot davies at stickyeyes dot com
If you create a DateTime object using a relative date string of "this week +6 days", when calling getTimestamp on the datetime object, the date is mysteriously increments by one day. However, if you seperately modify the datetime using 'this week', then '+6 days', it works correctly.

Where is the additional day comeing from, and why is it only applied when calling format('U') DOESNT increment the datetime by 1 day. Wierd!

Here is a work around:

$endOfWeek = new DateTime();
$endOfWeek->modify('this week');
$endOfWeek->modify('+6 days');

echo $endOfWeek->format('Y-m-d H:m:s')."\n";
echo $endOfWeek->format('U')."\n";

/* Thar she blows! */
echo $endOfWeek->getTimestamp()."\n";

echo $endOfWeek->format('Y-m-d H:m:s')."\n";

Test script:
$endOfWeek = new DateTime();
$endOfWeek->modify('this week +6 days');

echo $endOfWeek->format('Y-m-d H:m:s')."\n";
echo $endOfWeek->format('U')."\n";

/* Thar she blows! */
echo $endOfWeek->getTimestamp()."\n";

echo $endOfWeek->format('Y-m-d H:m:s')."\n";

Expected result:
DateTime should stay the same after a call to getTimestamp (surely getTimestamp should be safe from side effects)


52454_date_get_timestamp.patch (last revision 2010-08-20 10:03 UTC by mike at iammike dot co dot uk)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-27 11:59 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2010-08-20 11:43 UTC] mike at iammike dot co dot uk
I believe I've encountered the same bug although with slightly different 

Code to reproduce

$s = new DateTime;
$e = new DateTime("+3 months");
$i = new DateInterval("P1M");
$p = new DatePeriod($s, $i, $e);

foreach($p as $m) {
	echo $m->format("Y-m-d") . "\n";

Expected results

Actual results

I first encountered this in PHP 5.3.2-1ubuntu4.2 but I've verified it's still 
there in PHP 5.3.99-dev (trunk snapshot 201008200830).

Additional calls to getTimestamp cause the month to be incremented further.

Interestingly, if you swap "+3 months" for "+3 years" and "P1M" for "P1Y" the 
year is affected instead of the month.
 [2010-08-20 12:05 UTC] mike at iammike dot co dot uk
Removing the call to timelib_ts_update in date_get_timestamp as per 
52454_date_get_timestamp.patch fixes it.

I'm not sure if it's the right thing to do but I can't think of a good reason 
you'd need to update anything when retrieving a timestamp.
 [2010-08-30 18:25 UTC]
Automatic comment from SVN on behalf of derick
Log: - Fixed bug #52454 (Relative dates and getTimestamp increments by one day)
 [2010-08-30 18:26 UTC]
-Status: Assigned +Status: Closed
 [2010-08-30 18:26 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 11:01:28 2024 UTC