Get the quarter from a date

Here’s is a quick method of getting the quarter from a date. For example

MonthQuarter
1 – January 1
2 – February1
3 – March1
4 – April2
5 – May2
6 – June2
7 – July3
8 – August3
9 – September3
10 – October4
11 – November4
12 – December4
DateTime date = Convert.ToDate("5/10/2010");
decimal YearlyQuarter = Math.Ceiling(((decimal)date.Month / 12) * 4);

The above code will give a value of 2 to the YearlyQuarter variable because May is in the 2nd quarter of a year.

Leave a Comment