Filippo oretti
Filippo oretti

Reputation: 49817

Check if timestamp is expired by comparing that to current timestamp

i need to check if a timestamp is expired datetime, by comparing that to the current timestamp

So i have :

$current_timestamp = time();
$db_timestamp = 134500809

My dubt is, is it correct in all cases to do (is it always TRUE):

if($current_timestamp > $db_timestamp){
 // $db_timestamp is expired for sure
}

or should this be FALSE in some cases?

Upvotes: 0

Views: 2521

Answers (1)

Karl Laurentius Roos
Karl Laurentius Roos

Reputation: 4399

It will be false if the timestamp from the database is in the future, thus it will work properly.

Try inserting a row in your database and set the timestamp to time() + 3600, then you'll see that your if statement is correctly evaluated and returning false until one hour has passed.

Upvotes: 1

Related Questions