Created
February 11, 2020 19:37
-
-
Save thewhistler1/f40b308c4e334f82ff696474fafc3efe to your computer and use it in GitHub Desktop.
Get nearest Sunday's date from date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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