I need to echo some code or message on a page depending on the hour of the day. Just like a welcome message, "good evening", or "good afternoon"
I don't know hot to group certain hours and assign a message to each group like
from 1:00:00 pm to 4:00:00pm = "good afternoon" and from 4:00:01 to 8:00:00 = "good evening"
so far I have :
<?php
date_default_timezone_set('Ireland/Dublin');
$date = date('h:i:s A', time());
if ($date < 05:00:00 AM){
echo 'good morning';
}
?>
But I don't know how to pass the hours range an the messages.
?>
now check this
$hour
in your morning , afternoon , evening or night range and accordingly give the messageI thought this thread could use a nice one-liner:
If you check the highest hour first (evening), you can eliminate the range checks completely, and make a nice, more compact conditional statement.
...should get you started (timezone insensitive).