Google - ваш друг.
Месяцы:
public DateTime FirstDayOfMonthFromDateTime(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month, 1);
}
public DateTime LastDayOfMonthFromDateTime(DateTime dateTime)
{
DateTime firstDayOfTheMonth = new DateTime(dateTime.Year, dateTime.Month, 1);
return firstDayOfTheMonth.AddMonths(1).AddDays(-1);
}
Вы можете делать что-то подобное годами:
DateTime time = new DateTime(2011,1,1);
time.AddYears(1).AddDays(-1);
И week необходимо использовать CultureInfo.FirstDay (или все, что вы хотите установить в качестве первого дня недели, в некоторых странах это понедельник, иногда воскресенье).
/// <summary>
/// Returns the first day of the week that the specified
/// date is in using the current culture.
/// </summary>
public static DateTime GetFirstDayOfWeek(DateTime dayInWeek)
{
CultureInfo defaultCultureInfo = CultureInfo.CurrentCulture;
return GetFirstDateOfWeek(dayInWeek, defaultCultureInfo);
}
/// <summary>
/// Returns the first day of the week that the specified date
/// is in.
/// </summary>
public static DateTime GetFirstDayOfWeek(DateTime dayInWeek, CultureInfo cultureInfo)
{
DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;
DateTime firstDayInWeek = dayInWeek.Date;
while (firstDayInWeek.DayOfWeek != firstDay)
firstDayInWeek = firstDayInWeek.AddDays(-1);
return firstDayInWeek;
}