Skip to content

Instantly share code, notes, and snippets.

@royce002
Created January 15, 2020 16:29
Show Gist options
  • Save royce002/798affd8190c0e90c27aab1cc01061c7 to your computer and use it in GitHub Desktop.
Save royce002/798affd8190c0e90c27aab1cc01061c7 to your computer and use it in GitHub Desktop.
Sets the timezone, and checks current time to see if it lies between a start and ending range.
<?php
date_default_timezone_set('america/chicago');
$currentDayTime = new DateTime(); // Get Today's Date/Time
echo $currentDayTime->format('m-d-Y H:i') . "<br>";
$startDateTime = new DateTime('2020-01-15');
$startDateTime->setTime(8, 00);
echo $startDateTime->format('m-d-Y H:i') . "<br>";
$endDateTime = new DateTime('2020-01-15');
$endDateTime->setTime(10, 26);
echo $endDateTime->format('m-d-Y H:i') . "<br>";
if (($currentDayTime >= $startDateTime) && ($currentDayTime <= $endDateTime)){
echo "<h1>LETS DO STUFF</h1>";
}else{
echo "Date not in range";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment