1. Home
  2. Computing & Technology
  3. PHP / MySQL

Time Based PHP Greetings

By , About.com Guide

3 of 4

If it is PM

This bit of code would directly follow the code from the previous page.
elseif ($m == "PM")
{
if ($hour == 12)
{
echo "Good Afternoon!";
}
elseif ($hour < 7)
{
echo "Good Afternoon!";
}
elseif ($hour > 6)
{
echo "Good Evening!";
}
}
?>
This code checks to see if the $m variable is PM. If it is PM it then checks to see what time it is using our $hour variable. If it is 12 PM (noon) it tells the user "Good Afternoon!". It also says good afternoon if it is any time before 7PM. For times 7PM and later, it tells the user "Good Evening"!
Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Time Based Greetings - PHP Greeting Script

©2009 About.com, a part of The New York Times Company.

All rights reserved.