Linq group month by quarters

后端 未结 4 1468
一个人的身影
一个人的身影 2020-12-30 12:21

Is it possible to do a linq group by and group months into quarters, Ie Q1 Jan to apr etc etc

4条回答
  •  半阙折子戏
    2020-12-30 12:49

    Something like this

    Enumerable.Range(1,12)
        .Select(o => new DateTime(DateTime.Today.Year, o, 1))
        .GroupBy(o => (o.Month - 1) / 3)
    

提交回复
热议问题