简体   繁体   中英

Number of days between two time stamps

How can I calculate the number of days between two times, I have a one time field in my table name active_time , following is the code I have tried but it gives me number value around thousands whereas I have queried for number of days:

$now =strtotime("now"); // Current time
$your_date = $data[$i]['active_time'];
$datediff = $now - $your_date;
$value= floor($datediff/(60*60*24));

result:16569

The datediff is in milliseconds. You need to do.

Multiply by an additional 1000.

$value= floor($datediff/(1000*60*60*24));

试试: $value= ceil(abs($now - $your_date) / 86400);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM