Visual Basic Language Reference  

Year Function

Returns an Integer value from 1 through 9999 representing the year.

Public Function Year(ByVal DateValue As DateTime) As Integer

Parameter

DateValue
Required. Date value from which you want to extract the year.

You can also obtain the year by calling DatePart and specifying DateInterval.Year for the Interval argument.

Example

This example uses the Year function to obtain the year from a specified date. In the development environment, the date literal is displayed in short date format using the locale settings of your code.

Dim MyDate As Date
Dim MyYear As Integer
MyDate = #2/12/1969#   ' Assign a date.
MyYear = Year(MyDate)   ' MyYear contains 1969.

See Also

Day Function | Month Function | Now Property | Weekday Function | DatePart Function | System Namespace | DateTime Structure | ArgumentOutOfRangeException Class