Click here to Skip to main content
15,042,397 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to list only the last 2 years details from the table.
Table consists of date & event name.
I tried giving :
SQL
select * from event where d_date >= " + (DateTime.Now.Year-2).ToString("yyyy/MM/dd") + " order by (d_date) desc

but it shows error.

how to query for that?
Posted
Updated 21-May-13 5:30am
v2

SQL
select * from event where d_date >=  DATE_SUB(NOW(), INTERVAL 2 YEAR) order by (d_date) desc
   
v2
Comments
Maciej Los 21-May-13 11:33am
   
I would suggest to visit this link: http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html[^] too.
+5
SQL
SELECT * FROM event WHERE d_date >=  DATE_SUB(d_date, INTERVAL 2 YEARS) ORDER BY d_date DESC
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900