The First Sunday of the month

  • Thread starter Thread starter Guest
  • Start date Start date
Dim i As Integer, intFirstSunday As Integer
For i = 1 To 7
If WeekDay(DateSerial(Year(Date), Month(Date), i)) = vbSunday Then
intFirstSunday = i
Exit For
End If
Next i

Replace "Date" with whatever date value you are using.
 
Don't know if this is the quickest, but here is one way.

?DateAdd("d",1-
Weekday(DateSerial(Year(Date()),Month(Date()),7),1),DateSerial(Year(Date()),Month(Date()),7))
 
That gives you the day of the week, but not the date. I added a line to do
that

Dim i As Integer, intFirstSunday As Integer
Dim dtmFirstSunday as Date

For i = 1 To 7
If WeekDay(DateSerial(Year(Date), Month(Date), i)) = vbSunday Then
intFirstSunday = i
Exit For
End If
Next i

dtmFirstSunday = DateSerial(Year(Date), Month(Date), i)
 
' Annotated version, split to allow step through

Public Function FirstSunday(InputDate As Date) As Date
Dim Result As Date

' Avoid problems if run midnight on last day of month
Result = Date

' Change from current day of month to first day of month
Result = DateSerial( Year(Result), Month(Result), 1 )

'-----------------------------
'Day - Weekday() Value - Needed Offset
'Sun - 0 - 0
'Mon - 1 - 6
'Tue - 2 - 5
'Wed - 3 - 4
'Thu - 4 - 3
'Fri - 5 - 2
'Sat - 6 - 1

Dim Offset As Integer
Offset = (7 - Weekday( Result ))

' Deal with case of Sunday
Offset = (Offset Mod 7 )
'-----------------------------

Result = Result + Offset
FirstSunday = Result

End Function
Finding the nth Particular Weekday in a Month
http://msdn.microsoft.com/library/d...v/html/findingnthparticularweekdayinmonth.asp
 
Back
Top