|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-06-09 13:57 UTC] s dot rotondo90 at gmail dot com
Description:
------------
When subtracting days from the next day of the week and today is the same day of the week, strtotime use the current date instead.
Test script:
---------------
// Today is 09/06/2015
echo date('d/m/Y', strtotime('next tue'));
echo date('d/m/Y', strtotime('next tue -1 day'));
Expected result:
----------------
16/06/2015
15/06/2015
Actual result:
--------------
16/06/2015
08/06/2015
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 23:00:01 2025 UTC |
I used Tuesday because i saw that this happen when using the same day for the next week. For example today is Wednesday and if i try this: echo date('d/m/Y', strtotime('next wed -1 day')); the output will be: 09/06/2015 The "next wed" seems to be ignored as you said. But, if i try to do the opposite operation: echo date('d/m/Y', strtotime('next wed +1 day')); the output will be: 18/06/2015 This time "next wed" worked well.Due to ambiguities in the parser, this can not be fixed without re-doing the full parser architecture. I am therefore closing this ticket, as there is a reasonable workaround (you can do 'next mon' instead), or with descriptive steps: $d = (new DateTimeImmutable('2015-06-09'))->modify('next tue')->modify('-1 day'); echo $d->format('d/m/Y'), "\n";