Get Start(first) Date for a week, month and quarter utility functions

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);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: