比较MySQL日期?

时间:2011-02-08 13:32:12

标签: mysql

我有2列,开始和结束。

我需要过滤结果以确保今天的日期在开始和结束之间。日期以MM / DD / YYYY语法存储。例如02/05/2011

有人能告诉我这是怎么做的吗?

"SELECT * FROM albums WHERE active=1 AND ..."

感谢。

4 个答案:

答案 0 :(得分:1)

select
    *
from 
    albums
where
    active=1
    and STR_TO_DATE(begin_date,'%m/%d/%Y') <= CURDATE()
    and CURDATE() <= STR_TO_DATE(end_date,'%m/%d/%Y')

但日期不应存储为varchar。它们应存储为date s。

答案 1 :(得分:0)

尝试:

SELECT * 
FROM albums 
WHERE active=1 
AND (Comare_Value) between Start and End

答案 2 :(得分:0)

SELECT *
    FROM albums
    WHERE active=1
        AND start <= NOW()
        AND end >= NOW();

答案 3 :(得分:0)

SELECT
    *
FROM
    albums
WHERE
    active=1 
    AND CURRENT_DATE BETWEEN begin_date AND end_date;