Skip to content

Instantly share code, notes, and snippets.

@introwit
Created October 28, 2015 10:56
Show Gist options
  • Save introwit/8dbe76dee57033bfce1b to your computer and use it in GitHub Desktop.
Save introwit/8dbe76dee57033bfce1b to your computer and use it in GitHub Desktop.
Display Greetings (Morning/Evening)
<?php
/* This sets the $time variable to the current hour in the 24 hour clock format */
$time = date("H");
/* Set the $timezone variable to become the current timezone */
$timezone = date("e");
/* If the time is less than 1200 hours, show good morning */
if ($time < "12") {
echo "Good morning";
} else
/* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */
if ($time >= "12" && $time < "17") {
echo "Good afternoon";
} else
/* Should the time be between or equal to 1700 and 1900 hours, show good evening */
if ($time >= "17" && $time < "19") {
echo "Good evening";
} else
/* Finally, show good night if the time is greater than or equal to 1900 hours */
if ($time >= "19") {
echo "Good night";
}
?>
@t3chguru36
Copy link

t3chguru36 commented Jan 22, 2020

date_default_timezone_set('America/Chicago');
//Here we define out main variables
$welcome_string="Welcome!";
$numeric_date=date("G");

//Start conditionals based on military time
if($numeric_date>=0&&$numeric_date<=11)
$welcome_string="Good Morning!";
else if($numeric_date>=12&&$numeric_date<=17)
$welcome_string="Good Afternoon!";
else if($numeric_date>=18&&$numeric_date<=23)
$welcome_string="Good Evening!";

//Display our greeting
echo "$welcome_string";

works for me but I want to add div styles to the text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment