C# Calculate the current yearly quarter

January 12, 2017

What quarter is it? (Based on current date). Also calculate start of next quarter and end of current quarter.

//Get current quarter.
int currentQuarter = (DateTime.Now.Month - 1) / 3 + 1; 

//Get the first day of next quarter
DateTime nextQuarterStartDate = new DateTime(currentDate.Year, (currentQuarter - 1) * 3 + 1, 1);  

//Get the last day of current quarter
DateTime quarterEndDate = nextQuarterStartDate.AddDays(-1);  

Photo by Pixabay from Pexels