Possible Duplicate:
How do I determine if a given date is Nth weekday of the month?
How do i get the nth weekday of the month?
For ex.:
2nd Monday of “July 2010” = 07/12/2010.
Looking for a function like:
public DateTime GetNthWeekofMonth(DateTime date, int nthWeek, DayOfWeek dayofWeek)
{
//return the date of nth week of month
}
from the above, the parameters of the function will be (“Any Date in July 2010”, 2, Monday).
Use the following extension method:
You can then write
Or, as a function:
(I need to subtract one because
date.Next(dayOfWeek)is already the first occurrence of that day)