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
2010-01-17 18:55:14
+1 because its a tad easier on the eyes than Chacha102's example (which is good non the less)
Mr-sk
2010-01-17 18:56:45
Updated to check for 60 minutes
Chacha102
2010-01-17 19:07:41
+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
2010-01-17 18:55:15
Ah .. Thanks for the correct @therefromhere. Thanks for correcting it @Alix!
Chacha102
2010-01-17 19:04:59
+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
2010-01-17 19:00:15