Utilizzando il metodo di estensione scritto da Bert Smith nel This Answer Qui è il metodo IsThirdFridayInLastMonthOfQuarter
Che farà esattamente quello che stai cercando ing per:
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;
}
}
usarlo:
bool isThirdFriday = DateHelper.IsThirdFridayInLastMonthOfQuarter(date);
fonte
2012-05-03 09:05:56
possibile duplicato di [Come calcolare 2 ° Venerdì del mese in C#] (http://stackoverflow.com/questions/6140018/how-to-calculate-2nd-friday-of-month-in-c-sharp) –
possibile duplicate di [Come trovare il Venerdì 3 in un mese con C#?] (http://stackoverflow.com/questions/5421972/how-to-find-the-3rd-friday-in-a-month-with-c) – Stefan
Quindi, se la data è 2012-06-15 è che una partita? O è 2012-05-18 (mese prima della fine) che sarebbe la partita? – mattytommo