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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.