Reputation: 313
i write code in php for return true when time is between to 2 time
$camp_curr_time = date("H");
$time_from ='19';
$time_to = '10';
if($time_from<=$camp_curr_time && $time_to>=$camp_curr_time)
{
echo 'true';
}
else
{
echo 'false';
}
but problem is if now time is 9 its return false . but this time is between time from and time to .help me please or any change above code when return true between 2 times we use time from 01 to 24 hour we not use am or pm
Upvotes: 0
Views: 185
Reputation: 999
I think this is what you're trying to do:
$camp_curr_time = (int) date('G');
$time_from = 19;
$time_to = 10;
$eleven = 23;
if(($camp_curr_time >= $time_from && $camp_curr_time <= $eleven) || $camp_curr_time <= $time_to) {
echo 'true';
} else{
echo 'false';
}
So the true
time range is 19-23 and 0-10.
Upvotes: 3