Last active
May 18, 2018 12:52
-
-
Save fabienlege/6a7b698b5c1bb66d1f18690cf950ecd0 to your computer and use it in GitHub Desktop.
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 format_date_range($start_date, $end_date, $start_time = null, $end_time = null){ | |
$start_date = new \DateTime($start_date); | |
$end_date = new \DateTime($end_date); | |
$return = ''; | |
if($start_date->format('d/m/Y') != $end_date-> format('d/m/Y')){ | |
$return .= 'Du '.$start_date->format('d/m/Y').' '; | |
if($start_time){ | |
$return .= $start_time.' '; | |
} | |
$return .= 'au '.$end_date->format('d/m/Y').' '; | |
if($end_time){ | |
$return .= $end_time.' '; | |
} | |
} | |
else{ | |
$return .= 'Le '.$start_date->format('d/m/Y').' '; | |
if($end_time){ | |
$return .= 'de '.$start_time.' à '.$end_time; | |
} | |
else{ | |
if($start_time){ | |
$return .= 'à '.$start_time; | |
} | |
} | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment