php - Change days to hours with date_diff -


$time = whatever want $future_date = new datetime(date('r',strtotime($time))); $time_now = time(); $now = new datetime(date('r', $time_now)); interval = date_diff($future_date, $now); echo $interval->format('%h:%i'); 

when run this... output days, cant see them. how can roll days hours (like have 35 hours example)?

this part of longer script im writing, im aware there different ways of doing this....

edit

using answers below, i've come this:

$time = '2013-10-8 11:10:00'; $future_date = new datetime($time); $now = new datetime(); $interval = date_diff($future_date, $now); $text = $interval->days * 24 + $interval->h . ':' . $interval->i;  

i'm trying output hours , minutes in format (00:00), leading zeros. out of depth...

example how difference between dates/timestamps in hours:

$future = new datetime('@1383609600'); $now = new datetime; $diff = $now->diff($future); echo $diff->days * 24 + $diff->h; 

update: if wish format output numbers leading zeros, can use sprintf() or str_pad() function. example of sprintf() use:

echo sprintf('%02d:%02d', $diff->days * 24 + $diff->h, $diff->i); 

Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -