Nearly. You want to use ANDs not ORs
Code:<?php $hour = date("G"); if ($hour >= 0 && $hour <= 11) { echo "Good morning"; } else if ($hour >= 12 && $hour <= 17) { echo "Good afternoon"; } else { echo "Good evening"; } ?>
I am trying to get a simple What/If PHP statement working based on the time of my server. If its midnight->11am it should say Good Morning. Between 12noon & 5pm then Good Afternoon, otherwise Good Evening...
Should this code work?
Code:<?php $hour = date("G"); if ($hour >= 0 || $hour <= 11) { echo "Good morning"; } else { if ($hour >= 12 || $hour <= 17) { echo "Good afternoon"; } else { echo "Good evening"; } } ?>
Nearly. You want to use ANDs not ORs
Code:<?php $hour = date("G"); if ($hour >= 0 && $hour <= 11) { echo "Good morning"; } else if ($hour >= 12 && $hour <= 17) { echo "Good afternoon"; } else { echo "Good evening"; } ?>
Nothing to see here
Barry (11-05-11)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks