Created
January 10, 2023 20:05
-
-
Save BytesCrafter/88467b22b2782c5c4d3c8758b6b23f40 to your computer and use it in GitHub Desktop.
Check if time is in between PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$current = get_my_local_time('h:i a'); | |
$sunrise = "8:00 am"; | |
$sunset = "5:00 pm"; | |
$date1 = DateTime::createFromFormat('h:i a', $current); | |
$date2 = DateTime::createFromFormat('h:i a', $sunrise); | |
$date3 = DateTime::createFromFormat('h:i a', $sunset); | |
if ($date1 > $date2 && $date1 < $date3) { | |
echo 'enabled'; | |
} else { | |
echo "disabled"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment