Skip to content

Instantly share code, notes, and snippets.

@thewhistler1
Created February 11, 2020 19:37
Show Gist options
  • Save thewhistler1/f40b308c4e334f82ff696474fafc3efe to your computer and use it in GitHub Desktop.
Save thewhistler1/f40b308c4e334f82ff696474fafc3efe 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