PHP Challenge 8 - Good Morning, Good Evening, Good Night
We have already seen how we can use the DateTime class in PHP. In this challenge you need to check the time of day and then present an appropriate message.
No use input is required for this challenge.
Your completed script needs to check the hour of the day and present one of the following messages:
- if between 6 am and 12 noon: "Good morning"
- if between noon and 6pm: "I hope you enjoy your afternoon"
- if between 6pm and midnight: "Don't watch too much TV tonight"
- for all other hours: "Sleep tight"
Note that due to timezone settings on your server you may get the wrong answer.
You will therefore need to override the default timezone.
Would you like the solution to this challenge?
The full video solution together with downloadable code is available in the PHP for Beginners course.
This course is taught by Patrick Morrow, a national award-winning teacher, who is very active in the course and who provides full support.
To enrol in the course click here.
Your email address will not be published.
PHP for Beginners
FREE Code Snippets
FREE hints and tips delivered direct to you once per month.