Amitai Fensterheim
Amitai Fensterheim

Reputation: 841

Get the date of last September

How to I get the date of the first day of last September?

Example:

Upvotes: 0

Views: 57

Answers (2)

Gustav
Gustav

Reputation: 56026

You might do with a one-liner:

DateSeptemberFirst = DateSerial(Year(Date) - 1 + Month(Date) \ 10, 9, 1)

Change 10 to 9 if "last September" includes the current September.

Note integer division with a backslash.

Upvotes: 2

Andre
Andre

Reputation: 27644

DateSerial is your friend.

Function LastSeptemberOne() As Date

    Dim lYear As Long

    If Date > DateSerial(Year(Date), 9, 1) Then
        lYear = Year(Date)
    Else
        lYear = Year(Date) - 1
    End If

    LastSeptemberOne = DateSerial(lYear, 9, 1)

End Function

You haven't defined what should happen on Sept 01 - you may need to change > to >=.

Upvotes: 1

Related Questions