Skip to content

Instantly share code, notes, and snippets.

@armohamm
Forked from thewhistler1/getSunday.php
Created February 11, 2020 20:05
Show Gist options
  • Save armohamm/92e6e6055a275a5be82aaeb9625b8377 to your computer and use it in GitHub Desktop.
Save armohamm/92e6e6055a275a5be82aaeb9625b8377 to your computer and use it in GitHub Desktop.
Get nearest Sunday's date from date
function getSunday($date) {
$dow = strftime("%A", strtotime($date));
switch ($dow) {
case "Monday";
$date = date ('Y-m-d', strtotime ("$date - 1 days"));
return $date;
case "Tuesday";
$date = date ('Y-m-d', strtotime ("$date - 2 days"));
return $date;
case "Wednesday";
$date = date ('Y-m-d', strtotime ("$date - 3 days"));
return $date;
case "Thursday";
$date = date ('Y-m-d', strtotime ("$date - 4 days"));
return $date;
case "Friday";
$date = date ('Y-m-d', strtotime ("$date - 5 days"));
return $date;
case "Saturday";
$date = date ('Y-m-d', strtotime ("$date - 6 days"));
return $date;
case "Sunday";
$date = $date;
return $date;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment