For a table of the following testtable, if you want to query a date that is 30 years from now
You should use the following SQL statement:
SELECT * FROM Testtablewheretimestampdiff (Year,date,now ()) <30
This method, even if the date field is a varchar type, can be queried successfully.
Timestampdiff function, the first field is a unit, can be changed to second,day,month, etc.
and the following query method, considering that the 1985 difference from the present 30, although simple, but if the date of change, such as next year, this statement will be changed to 1986-1-1.
At the same time, the most deadly is if the date field is saved for various reasons using the varchar type,
You will not be able to query success at all.
SELECT * from Testtablewhere date> ' 1985-1-1 '
"Mysql" to find items that have a difference of X days from the nearest, SQL statement about date