Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

DateAndTime.Year(DateTime) Method

Definition

Namespace:
Microsoft.VisualBasic
Assembly:
Microsoft.VisualBasic.Core.dll
Assembly:
Microsoft.VisualBasic.dll
Source:
DateAndTime.vb
Source:
DateAndTime.vb
Source:
DateAndTime.vb
Source:
DateAndTime.vb
Source:
DateAndTime.vb

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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


Feedback

Was this page helpful?