Logo Luan Morina
Display a time-based greeting

Hello

PHP

<?php 
$vDate = new DateTime('now', new DateTimeZone('Europe/Amsterdam'));
$date = $vDate->format('H');
if ($date >= 6 && $date < 12) {
$greeting = "Good Morning";
$image = "morning.jpg";
} 
else if ($date >= 12 && $date < 18) {
$greeting = "Good Afternoon";
$image = "afternoon.jpg";
} 
else if ($date >= 18 && $date < 22) {
$greeting = "Good Evening";
$image = "evening.jpg";
} 
else if ($date >= 22 && $date < 4) {
$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>
   Time based greeting with PHP