|
Posted by Rauch Christian on 10/13/12 11:27
Marc schrieb:
> I've got the following PHP which is designed to display a greeting
> message (client's request, not my idea), but for some reason, it is
> displaying Afternoon, any time after 12 (ie. until midnight), does
> anyone have any ideas why?
>
> Thanks in advance,
>
> Marc
>
>
> --- PHP ---
> if (date ("G") < 12) {
> $timeOfDay = "Morning";
> } elseif (date ("G") < 18) {
> $timeOfDay = "Afternoon";
> } elseif (date ("G") < 24) {
> $timeOfDay = "Evening";
> } else {
> $timeOfDay = "Day";
> }
>
> $dateToday = date ("l jS F Y");
>
> --- HTML/PHP ---
> <p>Good <?= $timeOfDay ?>. Today is <?= $dateToday ?>.</p>
I just checked with the following code, and it displays the apropriate
message.
-----------------
<?php
$date=23;
if ($date < 12) {
$timeOfDay = "Morning";
} elseif ($date < 18) {
$timeOfDay = "Afternoon";
} elseif ($date < 24) {
$timeOfDay = "Evening";
} else {
$timeOfDay = "Day";
}
$dateToday = date ("l jS F Y");
?>
<p>Good <?= $timeOfDay ?>. Today is <?= $dateToday ?>.</p>
-rauch
[Back to original message]
|