tags:

views:

245

answers:

3

Hi, so I have these two time stamps in PHP

1253339331 1253338959

I want to be able to somehow get the hour difference between those to datetimes. Our users should only have 24 hours to login after their first attempt, so I need to find out if it's less than 24 hours to allow them to login again.

+2  A: 
( 1253339331 - 1253338959 ) / ( 60 * 60 )

This will give you number of hours between the two timestamps.

Salman A
... number of minutes ...
Zed
That's the number of minutes.
Justin Johnson
No, 60*60 is the number of seconds in an **hour**
mobrule
+3  A: 

Those times are just seconds since Jan 1 1970 (see Unix Time); you can just subtract the two, then divide by (60 sec/min * 60 min/hr) to convert the seconds to hours.

So in your case, the times were only (1253339331-1253338959)/3600 = 0.1 hours apart.

Mark Rushakoff
+5  A: 
if ((t2-t1)/3600) < 24 { ... }
Zed