PHP

Display a time based greeting

Good Evening

What does this PHP snippet do?

This PHP snippet determines the current time in the Europe/Amsterdam timezone and sets a greeting and an associated image based on the time of day.

PHP
<?php 
  $vDate = new DateTime('now', new DateTimeZone('Europe/Amsterdam'));
  $hour = (int)$vDate->format('G'); // 'G' gives 0-23 without leading zeros

if ($hour >= 6 && $hour < 12) {
  $greeting = "Good Morning";
  $image = "morning.jpg";
} 

elseif ($hour >= 12 && $hour < 18) {
  $greeting = "Good Afternoon";
  $image = "afternoon.jpg";
} 

elseif ($hour >= 18 && $hour < 22) {
  $greeting = "Good Evening";
  $image = "evening.jpg";
} 

elseif ($hour >= 22 || $hour < 6) {
  $greeting = "Good Night";
  $image = "night.jpg";
} 

else {
  $greeting = "Hello";
  $image = "art.jpg";
}

?>
HTML and PHP
<div class="demo-container" style='background-image:url("images/<?php echo $image;?>")'>
<h1><?php echo $greeting;?></h1> 
</div>