0

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

Burning Crystals
  • 1,157
  • 3
  • 19
  • 35
nomeer
  • 205
  • 3
  • 13
  • Is it `PHP`? If so, add it as a tag. – PM 77-1 May 14 '15 at 03:53
  • possible duplicate of [Converting timestamp to time ago in PHP e.g 1 day ago, 2 days ago...](http://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago) – Burning Crystals May 14 '15 at 03:55
  • It may help http://stackoverflow.com/questions/2040560/finding-the-number-of-days-between-two-dates – Ravi Singh May 14 '15 at 05:13

2 Answers2

0

The datediff is in milliseconds. You need to do.

Multiply by an additional 1000.

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

deluxes
  • 36
  • 5
0

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

Dawood Butt
  • 496
  • 6
  • 22