<?php
$date = (new \DateTime('28-05-2018'));
if (($weekDay = $date->format('N')) < 4) {
// If the date is already a Monday, return it as-is
$date->modify('next thursday');
} elseif ($weekDay > 4) {
// Otherwise, return the date of the nearest Monday in the past
// This includes Sunday in the previous week instead of it being the start of a new week
$date->modify('last thursday');
}
var_dump($weekDay);
var_dump($date);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
string(1) "1"
object(DateTime)#1 (3) {
["date"]=>
string(26) "2018-05-31 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}