I'm writing a script were I have to check if a time range is between two times, regardless of the date.
For example, I have this two dates:
$from = 23:00
$till = 07:00
I have the following time to check:
$checkFrom = 05:50
$checkTill = 08:00
I need to create script that will return true if one f the check values is between the $from/$till range. In this example, the function should return true because $checkFrom is between the $from/$till range. But also the following should be true:
$checkFrom = 22:00
$checkTill = 23:45
Following function works even for older versions of php:
based on 2astalavista's answer:
You need to format the time correctly, one way of doing that is using PHP's
strtotime()
function, this will create a unix timestamp you can use to compare.Try this:
Try this function:
demo