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.
Drop the first strtotime; the variable is already in timestamp form:
if ($ratesTimeStamp <= strtotime('-2 hours')) {
echo "OLDER";
} else {
echo "not older";
}
$testedTime = 1325960262;
$currentTime = time();
if($currentTime - $testedTime > 7200){
/// Older than 2 hours
}
来源:https://stackoverflow.com/questions/8771981/check-if-timestamp-is-x-hours-old