Get Week Of The Month C#

static int GetWeekNumberOfMonth(DateTime date) {
  date = date.Date;
  DateTime firstMonthDay = new DateTime(date.Year, date.Month, 1);
  DateTime firstMonthMonday = firstMonthDay.AddDays((DayOfWeek.Monday + 7 - firstMonthDay.DayOfWeek) % 7);
  if (firstMonthMonday > date) {
    firstMonthDay = firstMonthDay.AddMonths(-1);
    firstMonthMonday = firstMonthDay.AddDays((DayOfWeek.Monday + 7 - firstMonthDay.DayOfWeek) % 7);
  }
  return (date - firstMonthMonday).Days / 7 + 1;
}