lioslios Posted November 10, 2014 Share Posted November 10, 2014 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 Link to comment https://forums.phpfreaks.com/topic/292389-diffrence-betwean-times-ignore-day-change/ Share on other sites More sharing options...
Barand Posted November 10, 2014 Share Posted November 10, 2014 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 https://forums.phpfreaks.com/topic/292389-diffrence-betwean-times-ignore-day-change/#findComment-1496239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.