0

Possible Duplicate:
Subtracting dates in PHP

I have two Unix timestamps, how can I calculate the total number of days between them?

Community
  • 1
  • 1
  • You can use this - http://stackoverflow.com/questions/4837474/counting-hours-and-adding-minutes-in-time-in-php/4837607#4837607 – Bakudan May 04 '11 at 23:13

4 Answers4

5
$timestamp1 = x;
$timestamp2 = y;

$days_elapsed = floor(($timestamp2 - $timestamp1)/86400);

echo $days_elapsed;
Marty
  • 39,033
  • 19
  • 93
  • 162
1

Convert them to UNIX-timestamp (if they arent already), then just

$diff = abs($timestamp1 - $timestamp2);
$days = (int) ($diff / 60 / 60 / 24); 
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
0

something like this should do the trick:
$days = (strtotime($timestamp1)-strtotime($timestamp2))/(60*60*24);

Pav
  • 2,288
  • 4
  • 22
  • 25
0

This code should do the trick

$numDays = abs($timeOne - $timeTwo)/60/60/24;
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125