Santosh Khatri Santosh Khatri - 1 month ago 7
MySQL Question

how to shows rows after compare with datediff function in mysql?

I have following table:

+===========+============+
| titleName | date |
+===========+============+
| title1 | 2016-08-06 |
+===========+============+
| title2 | 2016-08-03 |
+===========+============+
| title3 | 2016-07-29 |
+===========+============+
| title4 | 2016-08-09 |
+===========+============+
| title5 | 2016-09-03 |
+===========+============+


I want to show only that rows who do not crossed the 90 days as per current date(2016-11-04) like below:

+===========+============+
| titleName | date |
+===========+============+
| title4 | 2016-08-09 |
+===========+============+
| title5 | 2016-09-03 |
+===========+============+


I am using following query but it is not showing my result

SELECT titleName, Datediff(NOW(), publish_date) AS datediff FROM myTable ORDER BY titleName DESC LIMIT 8


so please help me how do i find my result.

Answer

Use WHERE clause with an INTERVAL:

SELECT * FROM the_table WHERE `date` + INTERVAL 90 DAY >= NOW();