Edit

Share via


DateAndTime.Year(DateTime) Method

Definition

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

public:
 static int Year(DateTime DateValue);
public static int Year (DateTime DateValue);
static member Year : DateTime -> int
Public Function Year (DateValue As DateTime) As Integer

Parameters

DateValue
DateTime

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

Returns

An integer value from 1 through 9999 representing the year.

Examples

The following 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 thisDate As Date
Dim thisYear As Integer
thisDate = #2/12/1969#
thisYear = Year(thisDate)
' thisYear now contains 1969.

Remarks

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

Applies to

See also