开发者

Compare MySQL dates?

开发者 https://www.devze.com 2023-02-09 11:49 出处:网络
I have 2 columns, start and end. I need to filter the results to ensure that today\'s date is between start and end. The date is stored in MM/DD/YYYY syntax. e.g.开发者_运维问答 02/05/2011

I have 2 columns, start and end.

I need to filter the results to ensure that today's date is between start and end. The date is stored in MM/DD/YYYY syntax. e.g.开发者_运维问答 02/05/2011

Can anyone show me how this is done please?

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

Thanks.


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')

But dates shouldn't be stored as varchar. They should be stored as dates.


Try:

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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消