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

Edited by lioslios
Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.