Reputation: 8071
I have two 24-hour time values and want to compare them using PHP.
I have tried the following:
$time="00:05:00"; //5 minutes
if($time1<='00:03:00')
{
//do some work
}
else
{
//do something
}
Is this the correct way to compare 2 time values using PHP?
Upvotes: 22
Views: 40846
Reputation: 1780
Use the built-in function strtotime():
$time="00:05:00"; //5 minutes
if(strtotime($time)<=strtotime('00:03:00')) {
//do some work
} else {
//do something
}
Upvotes: 47
Reputation: 324750
Yes, that is correct. You don't need to convert to an integer because 24-hour format is such that the string value is in the exact same order as the numeric.
Upvotes: 11