Usando el método de extensión escrita por Bert Smith en This Answer Aquí se el método IsThirdFridayInLastMonthOfQuarter
que hará exactamente lo que buscas ing para:
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);
// CurDate = 2011.10.1 Occurance = 1, Day = Friday >> 2011.09.30 FIX.
if (fOc.Month < CurDate.Month) Occurrence = Occurrence + 1;
return fOc.AddDays(7 * (Occurrence - 1));
}
public static bool IsThirdFridayInLastMonthOfQuarter(DateTime date)
{
// quarter ends
int[] months = new int[] { 3, 6, 9, 12 };
// if the date is not in the targeted months, return false.
if (!months.Contains(date.Month))
return false;
// get the date of third friday in month
DateTime thirdFriday = date.NthOf(3, DayOfWeek.Friday);
// check if the date matches and return boolean
return date.Date == thirdFriday.Date;
}
}
Para usarlo:
bool isThirdFriday = DateHelper.IsThirdFridayInLastMonthOfQuarter(date);
posible duplicado de [Cómo calcular el segundo viernes del mes en C#] (http://stackoverflow.com/questions/6140018/how-to-calculate-2nd-friday-of-month-in-c-sharp) –
posible duplicado de [¿Cómo encontrar el 3er viernes en un mes con C#?] (http://stackoverflow.com/questions/5421972/how-to-find-the-3rd-friday-in-a-month-with-c) – Stefan
Entonces, si la fecha es 2012-06-15 ¿es eso coincidente? ¿O es 2012-05-18 (mes antes del final) que sería el partido? – mattytommo