Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I check if my daterange is between now?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading