What is the best way to figure out if timestamp 1263751023 was more than 60 min ago?
-
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.MZB– MZB2010-01-17 19:54:30 +00:00Commented Jan 17, 2010 at 19:54
3 Answers
$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.
2 Comments
time() returns a value in seconds - that should be > 60 * 60One 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
$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
($time + $hour < time())