Q: quarter's start and end dates

G

Guest

Hello,

In C#, I need to find StartDate and EndDate of a quarter for a given date.
How can I do that?
Thanks,
 
K

Karl Seguin

Don't think there's a built-in method, but isn't this pretty trivial.
Forgive me for being a n00b, but don't you just need to do:

//assumes August 1st is your business start of year
DateTime startOfNewYear = new DateTime(DateTime.Now.Year, 8,1);
DateTime startOfFirstQuarter = startOfNewYear;
DateTime startOfSecondQuarter = startOfNewYear.AddMonths(3);
DateTime startOfThirdQuarter = startOfNewYear.AddMonths(6);
DateTime startOfForthQuarter = startOfNewYear.AddMonths(9);

DateTime endOfFirstQuarter = startOfSecondQuarter.AddDays(-1);
DateTime endOfSecondQuarter = startOfThirdQuarter.AddDays(-1);
DateTime endOfThirdQuarter = startOfForthQuarter.AddDays(-1);
DateTime endOfForthQuarter = startOfNewYear.AddYears(1).AddDays(-1);

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top