Skip to content

Instantly share code, notes, and snippets.

@marknt15
Created May 29, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marknt15/521c833be5248f675ea7 to your computer and use it in GitHub Desktop.
Save marknt15/521c833be5248f675ea7 to your computer and use it in GitHub Desktop.
PHP DateTime usage - compare dates, subtract dates and get hours or days
<?php
$ammended_start = DateTime::createFromFormat('g:i a D j M', Request::input('ammended_start_' . $time_ammendments_id))->getTimeStamp();
$ammended_finish = DateTime::createFromFormat('g:i a D j M', Request::input('ammended_finish_' . $time_ammendments_id))->getTimeStamp();
$date1 = new DateTime(date("Y-m-d H:i:s", $v->start_timestamp));
$date2 = new DateTime(date("Y-m-d H:i:s", $v->finish_timestamp));
$diff = $date2->diff($date1);
$elapsed = $diff->format('%a days %h hours %i minutes %S seconds');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment