TOP

VBA Function: Year

Description

The VBA Year function returns an integer corresponding to the year of the specified date.


Syntax Year

Year(date)

VBA Year Example

Using the Year function to get relevant information from a date:

Sub YearExample1()
    
      maDate = #10/30/2020#
    
      MsgBox Year(maDate) 'Returns: 2020

End Sub

This function also accepts dates in text format:

Sub YearExample2()
    
      maDate="10/30/2020"
    
      MsgBox Year(maDate) 'Returns: 2020

End Sub
The function returns the current day: DAY.
The function returns the current month: MONTH.