0

Possible Duplicate:
Get time difference

Hi, i need to get time difference between two time in php.

$starttime=time();
$endtime=time();

how to get hour minute and second in php

thanks

Community
  • 1
  • 1
nsing
  • 9
  • 2

4 Answers4

3
echo ($endtime-$starttime);

Will get you the number of seconds.

If you need to know the hours you can do something like:

$seconds = ($endtime-$starttime);
echo floor($seconds/3600).' hours';
dynamic
  • 46,985
  • 55
  • 154
  • 231
2
$starttime=time();
$endtime=time();

$diff = $endtime - $starttime;
$hours = floor($diff / 3600);
$minutes = floor (($diff % 3600) / 60);
$seconds = $diff % 60;
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
0

you can use date_diff for this....

Anish
  • 2,889
  • 1
  • 20
  • 45
0

Take a look at strftime

$difference = $endtime-$starttime;
echo strftime('%H:%M:%S',$difference);
konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
  • Manual page here: http://uk2.php.net/manual/en/function.strftime.php Be warned, though, that this causes problems with timezones, as essentially you are taking the hours, minutes and seconds of a timestamp of seconds after the UNIX epoch. For instance, using a timestamp (the difference in this case) of `1` when the timezone is on BST gives the result `01:00:01`, which is obviously wrong. Setting `date.timezone` to `America/Denver` (as an example) now gives `17:00:01` for the timestamp of `1`. – Aether Jun 06 '11 at 09:45