php display text according to time

Asked

Viewed 194 times

1

I’m doing a portfolio page.

And I’m in doubt, if when the person accesses my site at night, display the message good night on the screen.

  • Related: https://answall.com/q/287647/99718

1 answer

2

date_default_timezone_set - sets the default time zone used by all date and time functions in a script

date - Format local date and time

date_default_timezone_set('America/Sao_Paulo');

$hour = date('H');

    if($hour >= 6 && $hour < 12) {
        echo "bom dia";
    }else if($hour >= 12 && $hour < 18) {
        echo "boa tarde";
    }else if($hour >= 18 && $hour < 24) {
        echo "boa noite";
    } else {
        echo "vai dormir";
    }

See working in PHP Sandbox, test PHP online

  • What is the use of $hour = (int)$hour;?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.