Furze Furze - 8 months ago 32
SQL Question

Selecting rows with timestamps set to the future

I have a table of adverts. These adverts have

columns, which are both of the

I need to select ones that are going to start in the next 24 hours, and, separately, ones that are going to end in the next 24 hours. I wrote the query
select * from slides where enabled = 1 and start <= NOW() + interval 24 hour
, which seemed to work at first.

The problem is, it also selects rows from a long time ago. I need it just to select ones starting between now and 24 hours from now.

What am I doing wrong?


So, use two comparisons:

select s.*
from slides s
where s.enabled = 1 and
      s.start <= NOW() + interval 24 hour and
      s.start >= NOW();