I am going to need to return a special value to tell me if the current time is within opening hours:
In table places
ID OPEN CLOSE
1 14:00 16:00
2 12:00 15:00
3 10:00 14:00
I need to return in the query a special field: PLACE_IS_OPEN – true or false.
so that the returned result when the time is 14:35 is:
ID PLACE_IS_OPEN
1 1
2 1
3 0
What would be a descent way to go about this?
Test that
TIME(NOW())lies between the open and close times and return its boolean result as a column. This will work as-is if yourOPEN,CLOSEare MySQL DATETIME or TIME columns.If these are character columns rather than proper
TIMEtypes, you will needSTR_TO_TIME()to convert themAnd MySQL should allow you to simplify the
CASEstatement away, since theBETWEENwill return a 0 or 1 as it is: