Jump to content

diffrence betwean times ignore day change


lioslios

Recommended Posts

hello guys

 

i have 2 time variables 

 

$time1 = 22:00;

$time2 = 03:00;

 

my $current_time is 01:00

 

how can i figure that $current_time is  betwean the $time1 and $time2

 

 

the 

 

if ($current_time > $time1 && $current_time < $time2)

 

works if the day not change! 

 

is any way to ignore the day change

 

 

thanks

Don't ignore the date change, check for it

$time1 = new DateTime('22:00');
$time2 = new DateTime('03:00');
$current_time = new DateTime('04:00');

if ($time2 < $time1) {
    $time1->sub(new DateInterval('P1D'));
}
if ($current_time > $time1 && $current_time < $time2) {
    echo "Between";
}
else {
    echo "Outside";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.