php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54909 Relative weekday modifications reset time values.
Submitted: 2011-05-23 15:55 UTC Modified: 2022-05-13 13:36 UTC
Votes:12
Avg. Score:4.2 ± 1.0
Reproduced:12 of 12 (100.0%)
Same Version:5 (41.7%)
Same OS:9 (75.0%)
From: salathe@php.net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: salathe@php.net
New email:
PHP Version: OS:

 

 [2011-05-23 15:55 UTC] salathe@php.net
Description:
------------
Date modifications utilizing the "weekdays" keyword change the resulting date to 
have zero values for hour/minute/second units.  Prior to PHP 5.3.6, the time 
values were unaffected.

Test script:
---------------
<?php 
    
$dt = new DateTime('2011-05-10 12:34:56', new DateTimeZone('UTC'));
$dt->modify('10 weekdays');
echo $dt->format('r');

?>

Expected result:
----------------
Tue, 24 May 2011 12:34:56 +0000

Actual result:
--------------
Tue, 24 May 2011 00:00:00 +0000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-24 11:04 UTC] salathe@php.net
-Assigned To: +Assigned To: derick
 [2015-09-23 17:34 UTC] jeff at nd4c dot com
This bug also applies to the strtotime() function.

<?php
$start = '2015-09-25 11:25:23';
$formats = array(
	'1 second',
	'1 minute',
	'1 hour',
	'1 day',
	'1 weekday',
	'1 weeks',
	'1 month',
	'1 year',
);
echo "Start\t\t\tDateTime\t\tstrtotime\t\tformat\n";
foreach ($formats as $format):
	$datetime = new DateTime($start);
	echo $datetime->format('Y-m-d H:i:s')."\t";
	$datetime->modify($format);
	echo date('Y-m-d H:i:s', strtotime($format, strtotime($start)))."\t";
	echo $format."\n";
endforeach;
?>

Outputs:

Start			DateTime		strtotime		format
2015-09-25 11:25:23	2015-09-25 11:25:24	2015-09-25 11:25:24	1 second
2015-09-25 11:25:23	2015-09-25 11:26:23	2015-09-25 11:26:23	1 minute
2015-09-25 11:25:23	2015-09-25 12:25:23	2015-09-25 12:25:23	1 hour
2015-09-25 11:25:23	2015-09-26 11:25:23	2015-09-26 11:25:23	1 day
2015-09-25 11:25:23	2015-09-28 00:00:00	2015-09-28 00:00:00	1 weekday
2015-09-25 11:25:23	2015-10-02 11:25:23	2015-10-02 11:25:23	1 weeks
2015-09-25 11:25:23	2015-10-25 11:25:23	2015-10-25 11:25:23	1 month
2015-09-25 11:25:23	2016-09-25 11:25:23	2016-09-25 11:25:23	1 year
 [2015-09-23 17:45 UTC] jeff at nd4c dot com
This bug has been verified that it still exists in the following versions:

PHP version 5.6.6 for Windows, Apache/2.4.12 (Win32)
PHP version 5.4.42 for Linux, Apache/2.2.15 (CentOS)
 [2016-06-10 03:05 UTC] amakhrov at gmail dot com
This still happens in php 7.0.x version (Linux, MacOSX)

Looks like the related behavior is defined here:
https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.re#L669..L673
 [2017-10-24 07:55 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
 [2021-09-21 12:45 UTC] cmb@php.net
Comparing <https://3v4l.org/OhHNJ> and <https://3v4l.org/N337o>
this looks like a bug to me, but after that long time, it might as
well be considered a documentation issue.
 [2022-05-13 13:36 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2022-05-13 13:36 UTC] derick@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php

This was fixed in 8.0.10 already, and is also related to #80409: https://www.php.net/ChangeLog-8.php#8.0.10
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 08:01:30 2025 UTC