Compare MySQL dates?
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 date
s.
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();
精彩评论