Reputation: 135
In MySQL db , I am storing values of time in "01:45:00 pm" format. Now I have to check whether current time is greator than database stored time. I have tried for:
<?php
$count = 0;
if('01:45:00 pm' >= '11:12:18 am')
{
$count++; //count is variable
}
echo $count;
?>
It's giving result as 0; So please help me.
Upvotes: 0
Views: 49
Reputation: 1094
Use objects rather than strings for your datetimes
<?php
$count = 0;
$time_1 = new DateTimeImmutable('01:45:00 pm');
$time_2 = new DateTimeImmutable('11:12:18 am');
if ($time_1 >= $time_2) {
$count++;
}
echo $count;
Upvotes: 2
Reputation: 5492
Just need to use strtotime:
<?php
$count=0;
if(strtotime('01:45:00 pm') >= strtotime('11:12:18 am'))
{
$count++;//count is variable
}
echo $count;
?>
Upvotes: 1