tags:

views:

77

answers:

3

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

+2  A: 

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
}
Gumbo
+1 because its a tad easier on the eyes than Chacha102's example (which is good non the less)
Mr-sk
Updated to check for 60 minutes
Chacha102
+5  A: 
$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.

Chacha102
+1, This is way easier to read.
Alix Axel
`time()` returns a value in seconds - that should be `> 60 * 60`
therefromhere
@therefromhere: I also noticing that, fixed.
Alix Axel
Ah .. Thanks for the correct @therefromhere. Thanks for correcting it @Alix!
Chacha102
+1  A: 
$hour = 60*60; // one hour


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

if ($time + $hour < time()) 
{
    // one hour a go
}
streetparade
That doesn't make sense... shouldn't it be `($time + $hour < time())`
Chacha102