totn Access Functions

MS Access: Year Function

This MSAccess tutorial explains how to use the Access Year function with syntax and examples.

Description

The Microsoft Access Year function returns a four-digit year (a number from 1900 to 9999) given a date value.

Syntax

The syntax for the Year function in MS Access is:

Year ( date_value )

Parameters or Arguments

date_value
A valid date.

Returns

The Year function returns a numeric value between 1900 and 9999.

Applies To

The Year function can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example

Let's look at how to use the Year function in MS Access:

Year (#22/11/2003#)
Result: 2003

Year (#01/01/1998#)
Result: 1998

Example in VBA Code

The Year function can be used in VBA code in Microsoft Access.

For example:

Dim LYear As Integer

LYear = Year(#12/03/2001#)

In this example, the variable called LYear would now contain the value of 2001.

Example in SQL/Queries

You can also use the Year function in a query in Microsoft Access.

For example:

Microsoft Access

In this query, we have used the Year function as follows:

Expr1: Year(#13/08/1985#)

and

Expr2: Year([CategoryDate])

The first Year function will extract the year value from the date 13/08/1985 and display the results in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.

For example:

YearValue: Year(#13/08/1985#)

The results would now be displayed in a column called YearValue.

The second Year function will extract the year value from the CategoryDate field and return the results in a column called Expr2.