Mark Topper Mark Topper - 6 months ago 19
PHP Question

Timestamp check if older than 12 hours

How can I check if a timestamp is older than 12 hours?

I need to make a link work for 12 hours, after that I need to display an error message.

Answer
$dateFromDatabase = strtotime("2012-12-04 12:05:04");
$dateTwelveHoursAgo = strtotime("-12 hours");

if ($dateFromDatabase >= $dateTwelveHoursAgo) {
    // less than 12 hours ago
}
else {
    // more than 12 hours ago
}