|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78080 strtotime('last <day of week> + 7 days') incorrect result
Submitted: 2019-05-29 03:29 UTC Modified: 2022-07-22 16:39 UTC
From: romash1408 at yandex dot ru Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 7.3.5 OS: UNIX
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.
Block user comment
Status: Assign to:
Bug Type:
From: romash1408 at yandex dot ru
New email:
PHP Version: OS:


 [2019-05-29 03:29 UTC] romash1408 at yandex dot ru
Today is 2019-05-29, wednesday.
In any php 7.* interpreter I write
echo date('Y-m-d', strtotime('last wednesday'));
and get last week's day (2019-05-22)

echo date('Y-m-d', strtotime('last wednesday + 1 day'));
shows correct date too (2019-05-23)

echo date('Y-m-d', strtotime('last wednesday + 7 day'));
gives result like 'last wednesday' was today (2019-06-05)

Live example on Ideone:

php 5.6 doesn't have this bug!

Test script:
$day = date("l");
echo date("Y-m-d", strtotime("last $day")) . "\n";
echo date("Y-m-d", strtotime("last $day + 1 day")) . "\n";
echo date("Y-m-d", strtotime("last $day + 6 day")) . "\n";
echo date("Y-m-d", strtotime("last $day + 7 day")) . "\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-01 14:40 UTC] leo dot sjoberg at gmail dot com
PR open at timelib:
 [2020-01-20 17:18 UTC]
-Assigned To: +Assigned To: derick
 [2020-01-20 17:28 UTC]
Related to Bug #78827
 [2022-07-22 16:39 UTC]
-Status: Assigned +Status: Not a bug
 [2022-07-22 16:39 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Having multiple stanzas working on the same field (the day) can not always be directly interpreted. In this case, the "last wednesday" and "+x day" simply conflict. In order to handle this correctly, you should split these stanzas up, like in:

echo (new DateTimeImmutable("2019-05-29"))->modify("last wednesday")->modify("+7 days")->format("Y-m-d"), "\n";

Which will output:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 20:01:29 2024 UTC