September 4th, 1999, 03:58 PM
Im very new to php and I havent gotten hold of the syntax yet.
I wanted to make a function that will print "Good Morning" on the screen if the $hour string is less than 12, "Good Afternoon" if less than 18, and "Good Evening" if anything else..
This is my code.
$hour = date("h");
if ($hour < 6)
print "Good Early Morning";
elseif ($hour < 12)
print "Good Morning";
elseif ($hour < 18)
print "Good Afternoon";
print "Good Evening";
Does anyone know what Im doing wrong?
September 4th, 1999, 05:41 PM
1) Get rid of that "endif". That will cause a parse error.
2) Use a capital H in date(). Lowercase returns a value 1-12. You need 0-23.
September 4th, 1999, 06:03 PM
Thanks Chris, It would be pretty funny if it said Good Evening to someone in the Middle East or other places when its Morning for them.