I have an application storing the times a restaurant is open:
My code to get the currently open restaurants. My SQL query (simplified) looks like
SELECT *
FROM `restaurants` r
WHERE r.from <= NOW()
AND r.to >= NOW();
The problem here is, there’s an entry which rolls over — it’s for a restaurant open from 11 AM to 3 AM the next day.
What would be a good query to capture that particular restaurant?
In pseudo code:
Converting that to SQL:
You might also want to check for places which are open 24 hours. The below code assumes that you would set the
fromandtotimes to be the same (eg: from midnight to midnight)