Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

getting last monday of the month

I have some code to get the first monday of each month

 Shared Function EarlyMay(ByVal theYear As Integer) As Date
        'first Monday in May
        Dim Dte As Date = New Date(theYear, "05", 1)

        Do While Dte.DayOfWeek <> DayOfWeek.Monday
            Dte = Dte.AddDays(1)
        Loop
        Return Dte
    End Function

Open in new window



how could i reverse this to get the LAST monday of each month?
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this




 Shared Function EarlyMay(ByVal theYear As Integer) As Date
        'first Monday in May
        Dim Dte As Date = New Date(theYear, "05", DateTime.DaysInMonth(theYear, 5))

        Do While Dte.DayOfWeek <> DayOfWeek.Monday
            Dte = Dte.AddDays(-1)
        Loop
        Return Dte
    End Function