VBA Functions: Day, Month, and Year
The VBA functions Day, Month, and Year return an integer corresponding to the day, month, or year of the specified date.
Usage:
Day(date)
Month(date)
Year(date)
Example of Usage
Using the Day, Month, and Year functions to retrieve corresponding information from a date:
Sub example()
myDate = #10/30/2024#
MsgBox Day(myDate) 'Returns: 30
MsgBox Month(myDate) 'Returns: 10
MsgBox Year(myDate) 'Returns: 2024
End Sub
These functions also accept date strings:
Sub example()
myDate = "10/30/2024"
MsgBox Day(myDate) 'Returns: 30
MsgBox Month(myDate) 'Returns: 10
MsgBox Year(myDate) 'Returns: 2024
End Sub