VBA Function: Date

The VBA function Date returns the current system date.

Usage:

Date


Examples of Usage

Save the date returned by the Date function in cell A1:

Sub example()

    Range("A1") = Date

End Sub

Display the date returned by the Date function in text format:

Sub example()

    MsgBox Format(Date, "mmmm d yyyy") 'Returns, for example: November 2 2024

End Sub

Perform an action only if the date returned by the Date function is the first day of the month:

Sub example()

    If Day(Date) = 1 Then
        MsgBox "It's the first day of the month!"
    End If

End Sub
The function that returns the current date as well as the current time is the Now function.