mysql - is today between two column values

邮差的信 提交于 2019-12-19 11:56:36

问题


| 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!