php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51188 strtotime - last dayofweek of the month feature request
Submitted: 2010-03-03 00:58 UTC Modified: 2017-01-12 20:53 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kbush at workforcerx dot org Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.13 OS: Windows 2003
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kbush at workforcerx dot org
New email:
PHP Version: OS:

 

 [2010-03-03 00:58 UTC] kbush at workforcerx dot org
Description:
------------
I was attempting to strtotime to find the last (specific) day of the month.
Example: Last Monday of May

But it returns false. I ended up taking a different approach but this would have 
been a nice feature.

Also tried: Last Monday April
Which did not return the results I was expecting.

Maybe we can get a little more documentation on this function and what terms it 
accepts? (If this exists, I was unable to find it)

Test script:
---------------
$f = "Y-m-d";$now = 1267571715; // 2010-03-02
echo "<pre>";
echo date($f, strtotime("last Monday",$now))."\n"; 
echo date($f, strtotime("last Monday in March",$now))."\n";
echo date($f, strtotime("last Monday of March",$now))."\n";
echo date($f, strtotime("last Monday April",$now))."\n";
echo date($f, strtotime("last Monday in April",$now))."\n";
echo date($f, strtotime("last Monday of April",$now))."\n";
echo "</pre>";

Expected result:
----------------
2010-03-01
2010-03-29
2010-03-29
2010-04-26
2010-04-26
2010-04-26

Actual result:
--------------
2010-03-01 (ok)
1969-12-31 (nothing returned)
1969-12-31 (nothing returned)
2010-03-29 (unexpected, but valid)
1969-12-31 (nothing returned)
1969-12-31 (nothing returned)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-12 20:53 UTC] heiglandreas@php.net
-Status: Open +Status: Not a bug
 [2017-01-12 20:53 UTC] heiglandreas@php.net
"in" does not work (as you can see from https://github.com/heiglandreas/php-src/blob/master/ext/date/lib/parse_date.re#L938. And as the "of" is mandatory appending a month to a valid "lastMonday" doesn't change the month. Therefore the "last Monday April" returns the last Monday calculated from the given datetime.

All other versions do work as you can see in https://3v4l.org/qQVC0
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC