issue with sql query to fetch records before 1 month from current date

Viewed 497

I am using MySQLi and I have SQL structure like This and I want all records which have expired date before 1 month

for that, I have tried

SELECT
    *
FROM
    new_domain
WHERE
    DATEPART( m, expire_date ) = DATEPART( m, DATEADD( m, -1, getdate() ) )
    AND
    DATEPART( yyyy, expire_date ) = DATEPART( yyyy, DATEADD( m, -1, getdate() ) )

but with that, I have receive an error #1305 - FUNCTION DATEPART does not exist

can anybody help me with this

2 Answers

I would use CURDATE() AND INTERVAL if I understand correctly your question: you are trying to select rows that expires in 1 month or less. Try this:

SELECT *
FROM new_domain
WHERE expire_date < CURDATE() - INTERVAL 30 DAY;
Related