jskidd3
jskidd3

Reputation: 4783

PHP: Check if MySQL time value is greater than 5 minutes

Difference is a MySQL time. I am trying to check if the MySQL time returned is greater than 5 minutes. I have tried the code below but it doesn't seem to be working.

if (strtotime($myMySQLTimeValue) > strtotime("+5 minutes",)) {
    // My code if MySQL time is greater than 5 minutes
}

Any ideas?

Upvotes: 2

Views: 1851

Answers (2)

Ahmad Essam
Ahmad Essam

Reputation: 1104

If you already have the time in the format 00:06:43 then you could use the following code

$diff_time = "00:06:43";
$diff_arr  = split(":", $diff_time);
// Check mins and hours
if ( intval($diff_arr[1]) >= 5 || intval($diff_arr[0]) > 0) {
    echo "Time more then 5 min";
} else {
    echo "Time less then 5 min";
}

Upvotes: 3

mesutozer
mesutozer

Reputation: 2859

Assuming you retrieved mysql time by "SELECT NOW()", you can use below comparison:

$_5minuteslater = time() + 5 * 60;
if ($mysqlTime > $_5minuteslater) {
}

Upvotes: 0

Related Questions