I am larning php and have got a simple task to be completed. But my brain is not working in coding the below requirement.

This is the requirement.

Create a form that contains:
1. Name, textbox
2. Submit button

If the user inputs the Name textbox and clicks the Submit button, the system must:
1. Display "Good morning, <Name>" if the server time is within 12am-12 noon
2. Display "Hello, <Name>" if the server time is not within 12am-12 noon
<Name> is the value as inputted by the user into the textbox

How can i design using only php ? is it possible ?


    echo "Good Morning <".$name.">";
    echo "Hello ".$name;


Now $today = " ? " which tag should i use to get the current date and time ?
This is just the conditions.
How to i insert a form to get the name ?

Try and see whether this works for you

$t = time();
if(date("H",$t) < 12)
    // Say Good Morning
    // Say Hello
Member Avatar

Niranga's code should work - perhaps the $t is overkill as I believe that date() takes this as default anyway.

However, this makes sense if everybody is on your timezone, if not, then it may appear a little strange.

@diafol: So true..!! I just checked running a sample code.. I get a few hours difference from my current time. Thanks a lot for the info :)