Edit report at https://bugs.php.net/bug.php?id=63521&edit=1
ID: 63521
Updated by: cmb@php.net
Reported by: linesarefuzzy at gmail dot com
Summary: Adding 5 weekdays to Fri, Sat or Sun results in
Sunday
-Status: Open
+Status: Closed
Type: Bug
Package: Date/time related
Operating System: Mac, Linux
PHP Version: 5.3.18
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Indeed, this bug has been fixed as of PHP 5.5.0, see
<https://3v4l.org/ED95p>.
Previous Comments:
------------------------------------------------------------------------
[2014-10-10 10:54:56] den4b at mail dot ru
Here is a simple workaround function for adding and subtracting weekdays:
function addWeekDays(DateTime $date, $numDays)
{
$numDays = (int)($numDays); // ensure integer!
$interval = new DateInterval('P1D'); // 1 day
while ($numDays != 0)
{
if ($numDays > 0)
$date->add($interval);
else
$date->sub($interval);
$dayOfWeek = $date->format('N'); // 1 (Monday) .. 7 (Sunday)
if (($dayOfWeek >= 1) && ($dayOfWeek <= 5))
{
if ($numDays > 0)
$numDays--;
else
$numDays++;
}
}
return $date;
}
------------------------------------------------------------------------
[2014-08-22 17:42:08] nabil at thinkshirt dot com
I am still having this issue. +10 and +5 give me the following Sunday instead of Friday on PHP
5.4.29.
------------------------------------------------------------------------
[2013-04-19 06:41:21] ravgu10 at gmail dot com
There is one more issue.
date('Y-m-d',strtotime(date('Y-m-d', strtotime('2013-04-22' . "
+5 Weekday"))));
Expected result: 2013-04-29 (Monday)
Actual result:2013-04-29 (Monday)
fine but when u do,
date('Y-m-d',strtotime(date('Y-m-d', strtotime('2013-04-29' . "
-5 Weekday"))));
Expected result: 2013-04-22 (Monday)
Actual result:2013-04-20 (Saturday)
------------------------------------------------------------------------
[2013-03-02 14:04:48] payden at paydensutherland dot com
This has been fixed (some time ago, Jul 29, in git). It's currently in the
latest 5.5-dev. It's not currently in latest 5.4, but I guess it should probably
make it there sometime.
------------------------------------------------------------------------
[2012-12-28 10:42:37] michal dot kocztorz at polcode dot pl
Seems to affect DateTime::modify too.
$dt = new DateTime("2013-01-04"); echo $dt->modify("+5
weekdays")->format("Y-m-d
H:i:s l") . "<br/>";
$dt = new DateTime("2013-01-05"); echo $dt->modify("+5
weekdays")->format("Y-m-d
H:i:s l") . "<br/>";
$dt = new DateTime("2013-01-06"); echo $dt->modify("+5
weekdays")->format("Y-m-d
H:i:s l") . "<br/>";
$dt = new DateTime("2013-01-07"); echo $dt->modify("+5
weekdays")->format("Y-m-d
H:i:s l") . "<br/>";
Got:
2013-01-13 00:00:00 Sunday
2013-01-13 00:00:00 Sunday
2013-01-13 00:00:00 Sunday
2013-01-14 00:00:00 Monday
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=63521
--
Edit this bug report at https://bugs.php.net/bug.php?id=63521&edit=1