Lets say shop is working from 8:00 till 23:00 and we use time format. Then it's easy. Some kind of:
where NOW() > start and NOW() < end
But what if shop working until 1:00am next day? And now exactly 23:00; So 23 > 1. This is will not gonna work.
So how to store and search business time in the correct way? Maybe in the end field better to store difference in seconds or i even don't know...
UPD: If you recommend use timestamp, then how i will find this time after one year, for example? We need to convert all dates to one?
The only solution that i decided use for now.
select * from times where ('05:00:00' between opens::time and closes::time) or ( closes::time < opens::time and '05:00:00' >= opens::time and '05:00:00' > closes::time ) or ( closes::time < opens::time and opens::time > '05:00:00' and closes::time > '05:00:00' ) and dow = 4 So for 13:00:00 - 04:00:00 I have results when variable is:
05:00:00- no results12:00:00- no results00:00:00- 1 row01:00:00- 1 row18:00:00- 1 row
If you have any better idea, please share
timeformat. Store it as atimestampand extract just thetimepart as per your need. You'll have serious compatibility issues. Redshift (based on Postgres) doesn't supporttimeas a datatype.2017-08-11 04:00:00. How i could find it in 2018?NOW()is a datetime, not just an hour.