public
Created

DateTime comparison (strings)

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11
<?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 ');
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.