Marverick M. Marverick M. - 1 year ago 57
PHP Question

days, hours, and miniutes remaining in php

I have this timestamp from the database


the problem is I don't know how to get the remaining days, hours and minutes

but I have this code bellow

this is my variable from where the timestamp stored

and now I have this current time now
$timenow = time();

I tried to calculate it with

$remainingtime = $db_user_timestamp - $timenow;

But I don't know how to put it in the days, hours and minutes.

Thanks in advance for helping me :)

Answer Source

Always use DateTime

$create_time = "1496592689";
$current_time = time();

$dtCurrent = DateTime::createFromFormat('U', $current_time);
$dtCreate = DateTime::createFromFormat('U', $create_time);
$diff = $dtCurrent->diff($dtCreate);

$interval = $diff->format("%y years %m months %d days %h hours %i minutes %s seconds");
$interval = preg_replace('/(^0| 0) (years|months|days|hours|minutes|seconds)/', '', $interval);

echo $interval;


 6 months 30 days 5 hours 52 minutes
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download