-3

I would like to Group values by month quarter. Supposing I have the following month quarters:

Month Range      Quarter Name
7->9             Q1
10->12           Q2
1->3             Q3
4->6             Q4

I want my results in linq to be grouped by Quarter based on Month number. How can I achieve this in linq?

ekad
  • 14,436
  • 26
  • 44
  • 46

2 Answers2

4

Try this using DateTime.Month:

var query = data.GroupBy(item => ((item.DateTimeProperty.Month - 1) / 3));
Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53
2

You can group by

(dateTime.Month-1)/3

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
EZI
  • 15,209
  • 2
  • 27
  • 33