John
John

Reputation: 103

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.

Upvotes: 0

Views: 1893

Answers (4)

vulkanino
vulkanino

Reputation: 9124

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

Upvotes: 0

Harry
Harry

Reputation: 4773

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

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37566

Try:

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

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691695

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.

Upvotes: 1

Related Questions