Year Function

Named Arguments





Use: Required

Data Type: Variant

Any valid date expression.

Return Value

A Variant of subtype Integer.


Returns an integer representing the year in a given date expression.

Rules at a Glance

If date contains Null, Year returns Null.

Programming Tips and Gotchas

  • The validity of the date expression and position of the year element within the given date expression are initially determined by the locale settings of the Windows system. However, some extra intelligence relating to two-digit year values (see next item) has been built into the Year function that surpasses the usual comparison of a date expression to the current locale settings.

  • What happens when you pass a date over to the Year function containing a two-digit year? Quite simply, when the Year function sees a two-digit year, it assumes that all values equal to or greater than 30 are in the 20th Century (i.e., 30 = 1930, 98 = 1998), and that all values less than 30 are in the 21st Century (i.e., 29 = 2029, 5 = 2005). Of course, if you don't want sleepless nights rewriting your programs in the year 2029, I'd suggest you insist on a four-digit year, which will see your code work perfectly for about the next 8,000 years!

See Also

DatePart Function, Day Function, IsDate Function, Month Function, Weekday Function

Get VB & VBA in a Nutshell: The Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.