Given a DateTime Object how can I check if the hour falls under a certain range?
$local_time = new DateTime();
//time is after 06:00:00 am
if (date('H', $local_time) >= 6) {
echo "After 6am";
}
Given a DateTime Object how can I check if the hour falls under a certain range?
$local_time = new DateTime();
//time is after 06:00:00 am
if (date('H', $local_time) >= 6) {
echo "After 6am";
}
DateTime objects are comparible:
$local_time = new DateTime();
$six_am = new DateTime('6am');
//time is after 06:00:00 am
if ($local_time > $six_am) {
echo "After 6am";
}
Note: this only works if the comparison is being done on the same day. It's gets more complex if you plan on crossing dates.