I have to do a mysql statement to get total items having date difference of more than 7 from today (means today – 7)
This is my current statement:
SELECT
COUNT(*)
FROM
complaints
WHERE
complaint_status = 'OPEN' AND
complaint_regdate <= curdate()
complaint_regdate >= DATE_SUB(curdate(),INTERVAL 7 day)
I am getting this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'complaint_regdate >= DATE_SUB(curdate(),INTERVAL 7 day)' at line 1
You can use the BETWEEN operator for this
Note you don’t need the DATE_SUB function, you can just use a normal subtraction.
Also these will only work if your
complaint_regdateis a DATE column. If it’s a DATETIME column you will need to use NOW() rather than CURDATE() or extract just the date pat of the field values.