Created
April 15, 2015 12:02
-
-
Save aembleton/6f7fbcb63f66f76a8713 to your computer and use it in GitHub Desktop.
PHP function to create a date range such as '1st - 4th May 2015' or '28th August - 2nd September 2015'
This file contains hidden or 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 getPrettyDateRange($fromDate, $toDate) { | |
$fromTime = strtotime($fromDate); | |
$toTime = strtotime($toDate); | |
$fromDay = date("jS", $fromTime); | |
$fromMonth = date("F", $fromTime); | |
$fromYear = date("Y", $fromTime); | |
$toDay = date("jS", $toTime); | |
$toMonth = date("F", $toTime); | |
$toYear = date("Y", $toTime); | |
$toDatePretty = $toDay." ".$toMonth." ".$toYear; | |
if ($fromYear != $toYear) { | |
return $fromDay." ".$fromMonth." ".$fromYear." - ".$toDatePretty; | |
} | |
if ($fromMonth != $toMonth) { | |
return $fromDay." ".$fromMonth." - ".$toDatePretty; | |
} | |
if ($fromDay != $toDay) { | |
return $fromDay." - ".$toDatePretty; | |
} | |
return $toDatePretty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment