hiiiii
I have some problem in linq date.
i want to select data by using year only
my database column date are present like 2014-05-6
but i want to select data by using year only i.e 2014 only
i am writing in sql like
select * from Holiday_List where YEAR(list_date)=2014
but i wants in this type query using LINQ .how is possible . give me example
but i wants in this type query using LINQ .how is possible . give me example
plz...
Thanx
Jignesh TrivediPosted May 6, 2014, 8:25 AM
Agree with nacro cheick.
if you date filed is nullable than try...
using(var contaxt = new yourDatacontext())
{
var query=from t in contaxt.holiday_List where t.list_date.HasValue && t.list_date.Value.Year==2014 select t;
}
also you can write your query by following way.
using(var contaxt = new yourDatacontext())
{
var query=contaxt.holiday_List.Where(t=> t.list_date.HasValue && t.list_date.Value.Year==2014);
}
hope this will help you.
nacro cheickPosted May 6, 2014, 7:44 AM
you can try this :
var query=from t in new yourDatacontext().Holiday_List where t.list_date.Year==2014 select t;