Common Date Time utility functions for figuring out start (first) dates
Week:
public static DateTime GetWeekStartDate(DateTime dDate) {
DayOfWeek day = dDate.DayOfWeek;
int days = day – DayOfWeek.Sunday;
DateTime start = dDate.AddDays(-days);
return start;
}
Month:
public static DateTime GetMonthStartDate(DateTime dDate)
{
int month = dDate.Month;
DateTime start = new DateTime(dDate.Year, month, 1);
return start;
}
Quarter:
public static DateTime GetQuarterStartDate(DateTime date)
{
int intQuarterNum = (date.Month – 1) / 3 + 1;
return new DateTime(date.Year, 3 * intQuarterNum – 2, 1);
}