开发者

best way to parse dates into month blocks

开发者 https://www.devze.com 2023-03-19 12:19 出处:网络
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,

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

精彩评论

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