Nitro Actually Sunday = 1, Monday = 2 etc. By default anyway. So I have assumed Friday = 6. I have tidied my routine up a little bit. If the first day of the month is after Friday (i.. Saturday, because Sunday is considered BEFORE Friday), I add 3 weeks instead of 2. Dim ExtraDays As Integer If Weekday(DateSerial(Year(Now), Month(Now), 1)) > 5 Then ExtraDays = 21 Else ExtraDays = 14 End If Debug.Print DateAdd("d", ExtraDays + (6 - Weekday(DateSerial(Year(Now), Month(Now), 1))), DateSerial(Year(Now), Month(Now), 1))
On the subject of calculating Easter, the following Excel worksheet formula is published in Walkenbach's Formula book. Even Walkenbach cannot explain how it works!! The 2007 is mentioned twice and is the year for which the calculation is required. It gives 8th April 2007 for this year, Easter Sunday, so it appears to work. =DOLLAR(("4/" & 2007)/7 + MOD(19*MOD(2007,19)-7,30)*14%,0)*7-6
Ruby: Code: require 'Date' def thirdFriday( date ) (date.wday == Date:: DAYS[ 'friday' ]) and (date.cweek - Date.new( date.year, date.mon, 1 ).cweek == 2) end
You have misunderstood. To "calculate whether a given day D is the 3rd Friday of the month", employ the single line return( (dayOfWeek(D) == FRIDAY) && (dayOfMonth(D) >= 15) && (dayOfMonth(D) <= 21) ) ;
This is what I have been using in VB (returns 3rd friday of the curr month): debug.Print (7 - (Weekday(Dateserial(Year(Now),Month(Now),1)) Mod 7) + 14) basically transforms Weekday result to 1=fri, 2=thu, 3=wed ... 7=sat then simply adds 14 to it