P
P
Pavel2018-03-26 23:09:47
PHP
Pavel, 2018-03-26 23:09:47

How to display an inscription depending on the time in php using strftime?

It is necessary, depending on the hour, to display this or that message using strftime.
What am I doing wrong?)
<?php
$hour = strftime("%H");
if ($hour >= 6 && $hour <= 9 ) {
echo "good morning"
{elseif ($hour >=21 && $hour <= 6){
echo "good afternoon";
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
riot26, 2018-03-26
@sidiqi

With brackets, complete rubbish, a semicolon is missing

$hour = strftime("%H");
if ($hour >= 6 && $hour <= 9 ) {
    echo "доброе утро";
} elseif ($hour >=21 && $hour <= 6) {
    echo "добрый день";
}

using a normal IDE or at least an editor with highlighting this error could have been avoided

S
Stalker_RED, 2018-03-27
@Stalker_RED

strftime returns a string and you compare it to a number.
The first condition will still work, thanks to automatic type casting, but the second is more difficult.
I'm trying to imagine which number is greater than 21, but at the same time less than 6, and I can't.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question