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

No comments yet

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: