Last active
November 2, 2019 04:05
-
-
Save robdecker/6694319 to your computer and use it in GitHub Desktop.
[Format 2 dates into a range string] #php
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
<?php | |
/** | |
* Format start/end dates of a range for printing to the screen. | |
* ex: "April 11 - 18, 2011" or "December 29, 2011 - January 3, 2012" | |
* | |
* @param DateTime $start : start of the range | |
* @param DateTime $end : end of the range | |
* @return string : the formatted string | |
*/ | |
function mnnshow_format_date_range($start, $end){ | |
if ($start->format('Y') == $end->format('Y') && $start->format('m') == $end->format('m')) { | |
return $start->format('F j - ').$end->format('j, ').$start->format('Y'); | |
} | |
elseif ($start->format('Y') == $end->format('Y')) { | |
return $start->format('F j - ').$end->format('F j, ').$start->format('Y'); | |
} | |
else { | |
return $start->format('F j, Y - ').$end->format('F j, Y'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment