<?php
function getStartOfWeekDate($date = null)
{
if ($date instanceof \DateTime) {
$date = clone $date;
} else {
// If date is falsy, it won't harm
$date = new \DateTime($date);
}
return $date->modify('monday this week');
}
echo getStartOfWeekDate(new \DateTime('2020-12-06'))->format('Y-m-d');
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
2020-11-30
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/En702 on line 4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/En702 on line 8
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/En702 on line 14
Fatal error: Call to a member function format() on a non-object in /in/En702 on line 14
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/En702 on line 4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/En702 on line 8
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/En702 on line 14
Fatal error: Class 'DateTime' not found in /in/En702 on line 14
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/En702 on line 4
Process exited with code 255.