Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created August 1, 2012 16:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save philsturgeon/3228499 to your computer and use it in GitHub Desktop.
Save philsturgeon/3228499 to your computer and use it in GitHub Desktop.
DateTime comparison (strings)
<?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