Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created August 1, 2012 16:12
Show Gist options
  • Save philsturgeon/3228301 to your computer and use it in GitHub Desktop.
Save philsturgeon/3228301 to your computer and use it in GitHub Desktop.
Tricky Date Formating
<?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