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

Time Based PHP Greetings

By Angela Bradley, About.com

1 of 4

Getting the Current Time

Before we can greet the user based upon the time of day, we first need to find out what time of day it is.
<?php

$b = time();

$hour = date("g",$b);
$m = date ("A", $b);

First we get the timestamp for the current date using the time () function. For the purpose of our script the only important parts are the hour and the AM/PM. We set a variable for each of these aspects of the time.

Index: Time Based PHP Greetings

  1. Getting the Current Time
  2. If it is AM
  3. If it is PM
  4. Full Code

1 of 4

Explore PHP / MySQL

More from About.com

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

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

All rights reserved.