JD333 :
given a users time, I am trying to figure out whether a store is open or closed.
My HoursOfOperation DB looks like this:
dayid | openTime | closeTime
3 1500 2400
4 1500 2400
5 1500 100
6 1500 200
dayid is sunday - saturday: 0-6 respectively.
openTime and closeTime range between 0-2400.
If the user time is say 1800 on a wednesday, that's easy. The place is open. But what if it's 1AM on a saturday? The greater than openTime returns false, and the less than closeTime check is true. false && true equals false.
I've tried multiple types of data and business logic. But I'm struggling to wrap my head around this. What am I missing?
Gordon Linoff :
You can use logic like this:
where dayid = @dayid and
( (openTime < closeTime and @timetocheck between openTime and closeTime) or
(openTime > closeTime and @timetocheck not between closeTime and openTime)
)
The logic reads as:
- If
openTime
is less thencloseTime
, then the store is open when the requested time is between them. - If
openTime
is greater thancloseTime
, then typicallycloseTime
would be in the wee hours of the morning. The store is closed between thecloseTime
andopenTime
. Hence, the store is open at other times.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=402190&siteId=1