1

What is the best way to figure out if timestamp 1263751023 was more than 60 min ago?

1
  • Presumably this is a filesystem time stamp or the result of a previous call to time() (For a database timestamp it's better to solve the problem in SQL). Note that there may be a significant clock skew between the filesystem and the PHP server in some installations. Presumably this doesn't matter here. Commented Jan 17, 2010 at 19:54

3 Answers 3

5
$time = 1263751023;
if((time() - $time) > 60 * 60)
{
   echo "Yes";
}

There are two basic way to figure this out. You can either figure out what an hour ago was and then check to see if the time you are checking was after that.

(time() - (60*60)) > $time;

The other way is you check what an hour after the time you are checking was, and see if that has passed yet.

($time + (60*60)) < time();

Oh, and the last is to check the difference between the two times, which will get you the number of seconds that have passed

(time() - $time) > (60*60)

All will get you the same answer.

Sign up to request clarification or add additional context in comments.

2 Comments

time() returns a value in seconds - that should be > 60 * 60
@therefromhere: I also noticing that, fixed.
2

One way is to calculate the difference between the one timestamp and the current timestamp:

$diff = time() - $timestamp;

And then test if that value is greater than 3600 (60 minutes with each 60 seconds):

$timestamp = 1263751023;
$diff = time() - $timestamp;
if ($diff > 3600) {
    // timestamp is more than 60 minutes ago
}

2 Comments

+1 because its a tad easier on the eyes than Chacha102's example (which is good non the less)
Updated to check for 60 minutes
1
$hour = 60*60; // one hour


$time = 1263751023; // zhere you could also use time() for now

if ($time + $hour < time()) 
{
    // one hour a go
}

1 Comment

That doesn't make sense... shouldn't it be ($time + $hour < time())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.