1

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.

3 Answers 3

6
if ((t2-t1)/3600) < 24 { ... } 
Sign up to request clarification or add additional context in comments.

Comments

3
( 1253339331 - 1253338959 ) / ( 60 * 60 ) 

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

2 Comments

That's the number of minutes.
No, 60*60 is the number of seconds in an hour
3

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.