In one line of code:
if (date('N', $date) > 5) $nextweekday = date('Ym-d', strtotime("next Monday", $date));
If the day of the week has a value greater than 5 (Monday = 1, Sat - 6, and Sun - 7), set $ nextweekday to YYYY-MM-DD next Monday.
Editing to add, since the date format cannot be accepted, you need to reformat the date first. Add the following lines above my code:
$pieces = explode('-', $date); $date = $pieces[0].'-'.$pieces[2].'-'.$pieces[1];
This will put the date in Ymd order so strtotime can recognize it.
source share