views:

103

answers:

2

I'm doing my final year project using asp.net as front end and SQL Server 2005 as back end

My question is: I want extract only the year from datetime format. And use the year to filter data

+2  A: 

In C#:

int year = DateTime.Now.Year;

If you mean at the T-SQL level:

DATEPART ("yyyy", date) 
Mitch Wheat
I'd prefer to use YEAR(date), since it's deterministic
marc_s
+2  A: 
priyanka.sarkar
I'd prefer to use YEAR(date) in T-SQL, since it's deterministic - DATEPART is **not** determistic, so you can't use it e.g. in a stored function or a field computation
marc_s
Thanks a lot. Something new to me.
priyanka.sarkar