LINQ - Extract Year in LinQ - Asked By Barbara M on 15-Dec-11 01:24 AM
friends,
I have one date filed in table... like
ID Date
----- -------
1 2026-04-18 00:00:00.000
2 2026-07-20 00:00:00.000
3 2025-08-11 00:00:00.000
I want to Extract the YEAR from the above dates in LINQ not in SQL.
Jitendra Faye replied to Barbara M on 15-Dec-11 01:29 AM
TRy like this=
var result= (from data in datasource
select data).ToList();
foreach(var item in result)
{
int year= (Convert.ToDateTime(item.Date)).Year;
}
Try this and let me know.
Riley K replied to Barbara M on 15-Dec-11 01:41 AM
You could try this way
Dim years = (From dy In dc.Dates
Select dy.Date1.Year).Distinct();
Regards
Barbara M replied to Jitendra Faye on 15-Dec-11 01:46 AM
Thanks Vickey... it works for me...
Jitendra Faye replied to Barbara M on 15-Dec-11 01:55 AM