0

I would like to get next day.

$nextSunday = date($saturdayList[$k], strtotime("+1 day"));

saturdayList array is

Array
(
    [
    0
] => 2022-11-05
    [
    1
] => 2022-11-12
    [
    2
] => 2022-11-19
    [
    3
] => 2022-11-26
)

When $k is 0 nextSunday return

2022-11-05

puss
  • 7
  • 4

2 Answers2

1

Please refer to the manual page for the date function here: https://www.php.net/manual/en/function.date.php.

You can see that the first param should be the format of the returned date, e.g. 'Y-m-d', not the date you want to add 1 day to.

The code should be something like

$nextSunday = date('Y-m-d', strtotime($saturdayList[$k] . " +1 day"));
Erebus
  • 1,998
  • 2
  • 19
  • 32
0

The second parameter of strtotime takes a base timestamp. So pass in the timestamp of the date as the second parameter.

$nextSunday = date("Y-m-d", strtotime("+1 day", strtotime($saturdayList[$k])));

Marshall C
  • 359
  • 3
  • 8