Click here to Skip to main content
15,881,559 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
 
Share this answer
 
v2
Comments
Maciej Los 21-May-13 11:33am    
SQL
SELECT * FROM event WHERE d_date >=  DATE_SUB(d_date, INTERVAL 2 YEARS) ORDER BY d_date DESC
 
Share this answer
 
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