Bug #75477 [Com]: last weekday of this month returns previous month when date is set
| From: | wouter at deinternetjonges dot nl | Date: | Fri, 03 Nov 2017 11:50:04 +0000 |
| Subject: | Bug #75477 [Com]: last weekday of this month returns previous month when date is set | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212423@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75477&edit=1
ID: 75477
Comment by: wouter at deinternetjonges dot nl
Reported by: wouter at deinternetjongens dot nl
Summary: last weekday of this month returns previous month
when date is set
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux, mac os
PHP Version: 7.1.11
Block user comment: N
Private report: N
New Comment:
Ok, so this is expected behaviour.
What we are trying to accomplish is getting the last weekday of a month.
So if it is a day between Monday till Friday I want to get the last day of those in a month.
Hope you get where I want to go to with this.
If it still is a feature request how can I ask for something like this to be added ?
Previous Comments:
------------------------------------------------------------------------
[2017-11-03 11:15:14] sjon at hortensius dot net
This is also described in the manual: http://php.net/manual/en/datetime.formats.relative.php
- so this is basically a feature request.
You could use
last friday of December 2017 instead, see https://3v4l.org/cVpin
------------------------------------------------------------------------
[2017-11-03 10:40:10] wouter at deinternetjongens dot nl
Expected result should be :
----------------
DateTime {#12086
+"date": "2017-12-29 00:00:00.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
------------------------------------------------------------------------
[2017-11-03 10:38:31] wouter at deinternetjongens dot nl
Description:
------------
We came across a bug when trying to get the last weekday of a month.
When we first setted a new date and afterwards modified it to get the last weekday of that month it
returns the last weekday of the month before the month given.
Test script:
---------------
$datetime = new DateTime()->setDate(2017, 12, 1);
var_dump($datetime->modify('last weekday this month');
Expected result:
----------------
DateTime {#12086
+"date": "2017-12-30 00:00:00.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
Actual result:
--------------
DateTime {#12086
+"date": "2017-11-30 00:00:00.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75477&edit=1