I have a field named time_range and its a daterange type.
my table is called holidays. I want to get all users where currently in a holiday. How can I to this with daterange type ?
I tried this but not working.
SELECT time_range FROM holidays WHERE upper(time_range) > NOW() AND lower(time_range) < NOW()
>Solution :
what do you mean not working?
anyway, i assume why your query is not working because there is possibility timerange same as now date.
in your query you should put <= and >=.
Solution:
SELECT time_range FROM holidays WHERE upper(time_range) >= NOW() AND lower(time_range) <= NOW()
or you can simplify your query
SELECT time_range FROM holidays WHERE time_range @> NOW();