Created
August 1, 2012 16:12
-
-
Save philsturgeon/3228301 to your computer and use it in GitHub Desktop.
Tricky Date Formating
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
<?php | |
function formatDate($strDate) { | |
$parts = explode(' ', $strDate); | |
$dates = explode('/', $parts[0]); | |
$times = explode(':', $parts[1]); | |
// check to see if it is am or pm | |
if(strtolower($parts[2]) == 'pm' && $times[0] != 12) { | |
// add 12 to the hour as it needs to be military time | |
$times[0]+=12; | |
} | |
return date('Y-m-d H:m:s', mktime($times[0], $times[1], $times[2], $dates[0], $dates[1], $dates[2])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment