问题
| id | first (datetime) | last (datetime)
--------------------------------------------------------
| 1 | 2013-04-15 00:00:00 | 2013-04-21 23:59:00
| 2 | 2013-04-08 00:00:00 | 2013-04-14 23:59:00
| 3 | 2013-04-01 00:00:00 | 2013-04-07 23:59:00
| 4 | 2013-04-01 00:00:00 | 2013-04-07 23:59:00
I want to show records if records datetime range covers today. (3 and 4 for this sample)
I tried do this with two NOW()
, it gives syntax error in second NOW()
.
How can i do this?
回答1:
select
*
from
your_table
where
first <= NOW()
and last >= NOW()
回答2:
select *
from your_table
where current_date() between first_datetime and last_datetime
来源:https://stackoverflow.com/questions/15817225/mysql-is-today-between-two-column-values