Programmatically locate date

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

Guest

Hi all,

Could you share with me how I can find the date of the first Monday of every
month programmatically? Thank you in advance.

Ben


--
 
Could you share with me how I can find the date of the first Monday of
every month programmatically? Thank you in advance.


Public Function FirstMondayIn(SomeYear As Integer, _
SomeMonth As Integer _
) As Date

FirstMondayIn = DateSerial(SomeYear, _
SomeMonth, _
8 - Weekday(DateSerial(SomeYear, SomeMonth, 0), vbMonday))

End Function

You can of course do this as an inline expression if you need to.

Hope that helps


Tim F
 
Pass this function any date in the month for which you want the first monday:

Function FindFirstMonday(dtmBaseDate As Date) As Date
'Returns the date of the first Monday in the month for the date passed
dtmBaseDate = DateSerial(year(dtmBaseDate), Month(dtmBaseDate), 1)
Do Until Weekday(dtmBaseDate) = vbMonday
dtmBaseDate = DateAdd("d", 1, dtmBaseDate)
Loop
FindFirstMonday = dtmBaseDate
End Function
 
Back
Top