Created
August 1, 2012 16:30
-
-
Save philsturgeon/3228499 to your computer and use it in GitHub Desktop.
DateTime comparison (strings)
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 calculateDateDiff($strStart, $strEnd) { | |
$objStart = DateTime::createFromFormat("m/j/Y g:i:s A", $strStart); | |
$objEnd = DateTime::createFromFormat("m/j/Y g:i:s A", $strEnd); | |
// Return Total Seconds | |
return $objEnd->getTimestamp() - $objStart->getTimestamp(); | |
// Return formatted diference (7hrs 5mins and 43 seconds) | |
return $objStart->diff($objEnd)->format('%hhrs %imins and %sseconds '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment