65.9K
CodeProject is changing. Read more.
Home

Get Quarter Starting and Ending Dates for a given Date

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.57/5 (4 votes)

Jul 19, 2010

CPOL
viewsIcon

60199

Get Quarter Starting and Ending Dates for a given Date

When you want the Quarter Starting and Ending dates for a given date, here are simple functions to calculate.
//whichQtr =  0 - present quarter
//           -1 - previous quarter
//            1 - next quarter
public static DateTime QuarterEnddate(DateTime curDate, int whichQtr)
{
   int tQtr = (curDate.Month - 1) / 3 + 1 + whichQtr;
   return new DateTime(curDate.Year, (tQtr * 3) + 1, 1).AddDays(-1);
}

public static DateTime QuarterStartDate(DateTime curDate, int whichQtr)
{
   return QuarterEnddate(curDate, whichQtr).AddDays(1).AddMonths(-3);
}