pietlinden@hotmail.com wrote:[color=blue]
> Hmm... step 1. get the first monday in july of the given year....
> something like this:
>
> Public Function FirstMonday(ByVal intMonth As Integer, intYear As
> Integer) As Date
> Dim dtDate As Date
> dtDate = DateSerial(intYear, intMonth, 1)
> Do Until Weekday(dtDate) = vbMonday
> dtDate = DateAdd("d", 1, dtDate)
> Loop
> FirstMonday = dtDate
>
> End Function[/color]
This can be calculated directly without looping.
New version of NthXDay function:
Public Function NthXDay(N As Integer, D As Integer, dtD As Date) _
As Integer
NthXDay = (7 - WeekDay(DateSerial(Year(dtD), Month(dtD), 1)) _
+ D) Mod 7 + 1 + (N - 1) * 7
End Function
This one-line function has been adjusted to use the default
firstdayofweek value for the WeekDay function.
Usage:
First Monday in July 2005:
NthXDay(1, vbMonday, #7/1/05#) ==> 4
BTW, I'm getting close to being finished with the documentation for the
Easter function solved by C. F. Gauss. I'll probably be done in about
two weeks. I have a few loose ends to tidy up and a few details left
to understand fully. Also, I'm looking into the possibility of a
simpler computation given that much of Gauss' method is for getting the
Sunday following a given date which can be done fairly easily using the
WeekDay function. Part of the bonus of doing all this additional
investigation is that I should be able to calculate moon phases and
other holidays that are based on lunar months. No holiday tables for
me!
James A. Fortune