Name
Year Function
Syntax
Year(date
)
-
date
Use: Required
Data Subtype: Date
Any valid date expression.
Return Value
A Variant of subtype Integer.
Description
Returns an integer representing the year in a given date expression.
Rules at a Glance
If date
contains Null
,
Year
returns Null
.
Programming Tips & 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 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 theYear
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, you should insist on a four-digit year, which will see your code work perfectly for about the next 8,000 years!
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.