Sheldon

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Has anyone ever run into a user written function that does the following

Function (intYear as integer, intMonth as integer, intDayOfWeek as integer, intCount as integer) as dat

WHERE based on what was passed in you would get back the date fo
2nd Monday of the month, o
Last Sunday of the month, o
FIrst Tuesday of the month, etc

Thanks
 
Specialized said:
Has anyone ever run into a user written function that does the following:

Function (intYear as integer, intMonth as integer, intDayOfWeek as integer, intCount as integer) as date

WHERE based on what was passed in you would get back the date for
2nd Monday of the month, or
Last Sunday of the month, or
FIrst Tuesday of the month, etc.

Here's a couple of functions for that:

Public Function NthWeekdayInMonthYear( _
intYear As Integer, _
intMonth As Integer, _
intDayOfWeek As Integer, _
intN As Integer _
) As Date
Dim dtBase As Date
dtBase = DateSerial(intYear, intMonth, 1)
NthWeekdayInMonthYear = dtBase + _
(intN * 7 + 1 - WeekDay(dtBase, intDayOfWeek))
End Function

Public Function LastWeekdayInMonth( _
intYear As Integer, _
intMonth As Integer, _
intDayOfWeek As Integer _
) As Date
Dim dtBase As Date
dtBase = DateSerial(intYear, intMonth + 1, 0)
LastWeekdayInMonth = dtBase + _
1 - WeekDay(dtBase, intDayOfWeek)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top