How can I get the date for Monday and Friday for the current week?
I have the following code, but it fails if current day is Sunday or Saturday.
$current_day = date("N");
$days_to_friday = 5 - $current_day;
$days_from_monday = $current_day - 1;
$monday = date("Y-m-d", strtotime("- {$days_from_monday} Days"));
$friday = date("Y-m-d", strtotime("+ {$days_to_friday} Days"));
Assuming your week starts on Monday you can use
DateTimeclass with specific relative formats.To get the Monday and Friday for the current week:
To get Monday and Friday relative to a specific date:
If your week starts on (for example) Sunday then you will have to calculate Monday and Friday manually. Here is an example: