php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69786 strtotime troubles when subtracting days
Submitted: 2015-06-09 13:57 UTC Modified: 2022-05-20 13:14 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: s dot rotondo90 at gmail dot com Assigned: derick (profile)
Status: Wont fix Package: Date/time related
PHP Version: 5.5.25 OS: Windows Server 2012 R2 Standard
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: s dot rotondo90 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-10 12:04 UTC] cmb@php.net
Hm, I'm not sure if that is supposed to work. Apparently 'next tue'
is simply ignored and only '-1 day' is calculated.

Anyhow, do you really mean 'next tue -1 day' instead of 'next
mon'? Both have, of course, different results on Mondays.
 [2015-06-10 13:10 UTC] s dot rotondo90 at gmail dot com
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.
 [2015-06-10 13:36 UTC] derick@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2021-10-28 15:29 UTC] cmb@php.net
Still behaves this way: <https://3v4l.org/9cApu>.
 [2022-05-20 13:14 UTC] derick@php.net
-Status: Assigned +Status: Wont fix
 [2022-05-20 13:14 UTC] derick@php.net
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";
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC