Reputation: 16724
I have a data in a text file saved using date("Y-m-d h:i:s", strtotime("+2 minutes"))
that I need to check if it's 10 minutes ago. I'm trying the following code but it doesn't print anything even if more than 10 minutes ago.
$now = date("Y-m-d h:i:s", strtotime("now"));
if($now > strtotime($old_data))
echo 'expired!';
Upvotes: 5
Views: 18829
Reputation: 3228
You should change either of the following:
$now = strtotime(date("Y-m-d h:i:s", strtotime("now")));
or
if (strtotime($now) > strtotime($old_data))
I'll go for the second. You are comparing a timestamp over date that is why you are not satisfying the condition of if()
.
Furthermore, you can also use time()
if you're only concern is the current timestamp.
$now = time();
or
$now = date("Y-m-d h:i:s", strtotime("now")); // Remove this line
if(time() > strtotime($old_data)) // Change $now with time()
Upvotes: 2
Reputation: 224
your comparing a formatted date with a time stamp which explains why nothing works
here:
$now = strtotime("-10 minutes");
if ($now > strtotime($old_data) {
echo 'expired!';
}
Upvotes: 14