Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sharim's avatar

Change text according to the date and time

I have a shop page where I want to show

We're Open

if the day is between Monday and Thursday and time is between 10:00 to 23:00. And

We're Closed

If the time is other than 10:00 to 23:00.

I'm storing these values in database like this:

|	From	|		To		| 	Time Open 	|	Time Close	|			//Column Names
|	Monday	|	Thursday	|	    10:00 	 |		23:00   |			//Sample Values
0 likes
4 replies
click's avatar

You can just do a simple if condition: the hour of the day muts be between 10 and 23

(now()->hour >= 10 && now()->hour < 23) ? "We're Open" : "We're Closed";

and if you are closed in the weekend:

(now()->isWeekday() && now()->hour >= 10 && now()->hour < 23) ? "We're Open" : "We're Closed";

This does assume that now() is returning the correct time in your timezone.

1 like

Please or to participate in this conversation.