开发者

best way to parse dates into month blocks

Given x amount of dates and the fiscal month being 1st-31st:

What's the best way to gr开发者_JAVA技巧oup the months. For example,

a date range of Jan 15 - Feb 15 are considered 2 items


var dateGroups = myDates.GroupBy(d => d.Month);

and as brought up, years would be useful

var dateGroups = myDates.GroupBy(d => d.Month)
    .Select(g => new {year = g.Key, monthGrouping = g.GroupBy(d => d.Month)})
    .SelectMany(a => a.monthGrouping
        .Select(g => new {a.year, month = g.Key, dates = g.AsEnumerable()}));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜