The VBA DAY Function

Related Functions:
VBA Month
VBA Year

Description

The VBA Day Function returns the day number (from 1 to 31) of a supplied date.

The syntax of the function is:

Day( Date )

VBA Day Function Example

A simple example of the VBA Day function is shown below:

' Extract the day component from the date "11/29/2015"
Const currDate = "11/29/2015"
Dim dayNum As Integer
dayNum = Day(currDate)
' The variable dayNum is now equal to 29.

After running the above VBA code, the variable dayNum holds the value 29, (the day number of the date "11/29/2015").


VBA Day Function Error

If the Day function is supplied with a value that cannot be interpreted as a valid date, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box