Skip to main content
Previous section

Year

Returns the year as a four-digit integer.

Synopsis

Year(date)

Arguments

The date argument is any expression that represents a date as a string.

Description

The Year function locates and returns the year portion of a date string as a four-digit integer. The Year function accepts blanks, slashes (/), hyphens (-), or commas (,) (in any combination) as date component separators.

The Year function locates the year portion, by position, as the third portion of a date. For example, “9/27/2005” or “September 27, 2005” or “27 September 2005”. It does not validate the day or month components of the date string.

If the Year function is unable to identify a year portion of the string, it returns a default value of “2000”. If the year portion is provided as a two-digit year, the Year function returns a four-digit year. If the two-digit year is 29 or less, it supplies ”20” for the missing century digits. If the two-digit year is greater than 29, it supplies 19” for the missing century digits.

Examples

The following example uses the Year function to return the current year:

Dim CurrYear
CurrYear = Year(Date)
Print CurrYear
Copy code to clipboard

The following example uses the Year function to obtain the year from a series of specified dates. In every case except the last, it returns the string “2005”. In the last case, the third portion of the string cannot be parsed as a year; this Year function instead returns the default value “2000”.

Dim YearA, YearB, YearC, YearD, YearE,YearF,YearG
YearA = Year("August 12 2005")
YearB = Year("Agosto 12 2005 11:35am")
YearC = Year("Aug 12 05 11:35am")
YearD = Year("12 Agosto 2005")
YearE = Year("8/12/2005")
YearF = Year("8-12-05 11:35am")
YearG = Year("August 12 11:35am")
Println YearA
Println YearB
Println YearC
Println YearD
Println YearE
Println YearF
Println YearG
Copy code to clipboard

See Also