Assuming that var stays = List<Stay>();
, you may try this:
var days = stays.SelectMany(s =>
Enumerable
.Range(0, (s.ToDate - s.FromDate).Days + 1)
.Select(d => s.FromDate.AddDays(d)))
.GroupBy(d => d.Year)
.Select(s => new { Year = s.Key, TotalDays = s.Count() })
.ToList();
days.ForEach(d =>
{
Console.WriteLine("{0} {1}", d.Year, d.TotalDays);
});
The output of the above is:
2001 32
2002 137
2003 60
2009 334
2010 32
2013 365
2014 365
2015 33