Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if timestamp is x hours old?

Tags:

php

strtotime

Simple question, but I couldn't find any related topics that match this exact scenario. Everything I found involved MySQL or date and time rather than just time.

I have a timestamp stored in a variable in the format of:

1325960262

Produced by:

$newTimeStamp = time();

How can I check if this timestamp is older than 2 hours?

I tried:

if (strtotime($ratesTimeStamp) <= strtotime('-2 hours')) {
    echo "OLDER";
} else {
    echo "not older";
}

But no luck.

like image 745
tctc91 Avatar asked Jan 07 '12 18:01

tctc91


1 Answers

Drop the first strtotime; the variable is already in timestamp form:

if ($ratesTimeStamp <= strtotime('-2 hours')) {
    echo "OLDER";
} else {
    echo "not older";
}
like image 175
Tim Cooper Avatar answered Sep 25 '22 06:09

Tim Cooper