Created
May 29, 2015 07:29
-
-
Save marknt15/521c833be5248f675ea7 to your computer and use it in GitHub Desktop.
PHP DateTime usage - compare dates, subtract dates and get hours or days
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 | |
$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