Archive for the ‘.NET 3.5’ Category

Get WeekDays in a Month (C# 3.0)

var weekends = new DayOfWeek[] { DayOfWeek.Saturday, DayOfWeek.Sunday };

 

DateTime calendarMonth = DateTime.Parse(“10/1/2008”);

 

int totalDays = DateTime.DaysInMonth(DateTime.Now.Year, calendarMonth.Month);

 

IEnumerable<int> businessDays = Enumerable.Range(1, totalDays)

.Where(d => 

!weekends.Contains(new DateTime(DateTime.Now.Year, calendarMonth.Month, d).DayOfWeek)

)

;

 

//loop through businessDays or get a count…

Advertisements