How to calculate the time difference between two timestamps in php?

qptopm

Newbie
Joined
Jul 31, 2014
Messages
38
Reaction score
5
How to calculate the time difference between two timestamps in php?
 
From Stack Overflow, the "go to" site for programming questions ->
$start_date = new DateTime('2007-09-01 04:1058');
$since_start = $start_date->diff(new DateTime('2012-09-11 10:25:00'));
echo $since_start->days.' days total<br>';
echo $since_start->y.' years<br>';
echo $since_start->m.' months<br>';
echo $since_start->d.' days<br>';
echo $since_start->h.' hours<br>';
echo $since_start->i.' minutes<br>';
echo $since_start->s.' seconds<br>';
 
I'd always post this sort of thing in stack over flow mate, you'll get a response super quick. Its by far the best site for coding problems.
 
Have a look into Carbon if you do a lot with datetime it's really quite useful.https://github.com/briannesbitt/Carbon

Jamie3000 is right, coding questions are best asked on stack overflow. You can usually Google search the question like 'php calculate timestamp difference' or similar and get an instant answer from there or some other helpful tech blogger
 
Back
Top