VB6 - Find first and second sunday dates of 2 months


I'm trying to find the second Sunday date of February from current year and also the first Sunday date of December from current year.

The first Sunday date of February of current year would show in Text1 and the second Sunday date of December of current year would show in Text2.

How can i do this.

Thank you for your help
LVL 11
Who is Participating?
This expert suggested creating a Gigs project.
Use this function:
Function GetNthWeekdayInMonth(iYear As Integer, iMonth As Integer, iTargetDOW As Integer, n As Integer) As Date
    Dim iFirstWeekDayOfMonth As Integer
    Dim dtFirstiTargetDOWinMonth As Date
    Dim dtFirstWeekday As Date
    iFirstWeekDayOfMonth = Weekday(DateSerial(iYear, iMonth, 1))
    dtFirstiTargetDOWinMonth = DateSerial(iYear, iMonth, 1 + ((iTargetDOW - iFirstWeekDayOfMonth + 7)) Mod 7)
    GetNthWeekdayInMonth = DateAdd("d", 7 * (n - 1), dtFirstiTargetDOWinMonth)
End Function

Open in new window

So for the second Sunday in February
Text1.text = GetNthWeekdayInMonth(Year(Now), 2, vbSunday, 2)

Open in new window

and the first Sunday in December:
Text2.Text = GetNthWeekdayInMonth(Year(Now), 12, vbSunday, 1)

Open in new window

I seem to have clicked on the wrong thing, This question does not warrant a Gigs project.
Wilder1626Author Commented:
This is exactly what i needed. Thank you for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.