Reputation: 176
I am using this query to get dates from MYSQL DB to show before current date. I want to show records using the current system date and before 3 days
SELECT gsu.id, gsuo.user_id, gsob.imei, gsob.vin, gsob.dt_tracker
FROM gs_users gsu
INNER JOIN gs_user_objects gsuo
ON gsu.id = gsuo.user_id
INNER JOIN gs_objects gsob
ON gsuo.imei = gsob.imei
WHERE gsu.id = '14' AND gsob.dt_tracker < CURDATE() AND vin <> ''
I have also tried
DATEADD(day, -3, gsob.dt_tracker)
AND
DATEADD(day, -3, GETDATE())
The result then does not show.
Upvotes: 0
Views: 508
Reputation: 513
For MySQL you need to use DATE_ADD()
function with interval parameter
date_add(curdate(), interval -3 day) -- today minus 3 days
Here's dbfiddle example how to use.
Upvotes: 3