I have a table returning the following result set:
mydate | startstop
------------+----------
2018-02-07 | start
2018-02-14 | stop
2017-02-06 | start
2017-02-12 | stop
2016-02-05 | start
2016-02-12 | stop
I need to know if my current date is in one of the intervals, for example if I query the table from the current date '2017-02-07'
, I need to get 'TRUE'
.
I know it looks like that simple but it is not being simple!
The best that I found is this:
select true
where '2017-02-06'>=
(select mydate from mytable where starstop='start' order by id limit 1)
and '2017-02-06' <=
(select mydate from mytable where startstop='stop' order by id limit 1);
It works returning TRUE
if the date is in one of each intervals, but only if the table does not have intervals in the future, and as you can see my table has intervals in the future.
Note: The database management system is PostgreSQL 9.1
'2018-02-14'
should you get true as result or false?