Skip to content

Instantly share code, notes, and snippets.

@BytesCrafter
Created January 10, 2023 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BytesCrafter/88467b22b2782c5c4d3c8758b6b23f40 to your computer and use it in GitHub Desktop.
Save BytesCrafter/88467b22b2782c5c4d3c8758b6b23f40 to your computer and use it in GitHub Desktop.
Check if time is in between PHP
$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