, IsThirdFridayInLastMonthOfQuarter , :
public static class DateHelper
{
public static DateTime NthOf(this DateTime CurDate, int Occurrence, DayOfWeek Day)
{
var fday = new DateTime(CurDate.Year, CurDate.Month, 1);
var fOc = fday.DayOfWeek == Day ? fday : fday.AddDays(Day - fday.DayOfWeek);
if (fOc.Month < CurDate.Month) Occurrence = Occurrence + 1;
return fOc.AddDays(7 * (Occurrence - 1));
}
public static bool IsThirdFridayInLastMonthOfQuarter(DateTime date)
{
int[] months = new int[] { 3, 6, 9, 12 };
if (!months.Contains(date.Month))
return false;
DateTime thirdFriday = date.NthOf(3, DayOfWeek.Friday);
return date.Date == thirdFriday.Date;
}
}
To use it:
bool isThirdFriday = DateHelper.IsThirdFridayInLastMonthOfQuarter(date);
user915331
source
share