How to group dates by week?

后端 未结 4 1549
死守一世寂寞
死守一世寂寞 2020-12-15 04:18

I am writing an Excel exporter for a bespoke application I am creating, and I have a question about LINQ grouping in C#.

Basically, this new Excel exporter class is

4条回答
  •  情书的邮戳
    2020-12-15 05:06

    I tried like this (and it's working :) )

    @foreach (var years in _dateRange.GroupBy(y => y.Year))
    {
        

    @years.Key

    foreach (var months in years.GroupBy(m => m.Month)) {

    @CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(months.Key)

    foreach (var weeks in months.GroupBy(w => w.AddDays(-(int)w.DayOfWeek))) {

    @weeks.Key.ToString("dd-MMM-yy")

    } } }

提交回复
热议问题