Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

Year Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

Year(datevalue)
datevalue (required; Date or valid date expression)

Any valid date expression

Return Value

Integer

Description

Returns an integer representing the year in a given date expression

Rules at a Glance

  • If datevalue contains Nothing, Year returns 1. (This assumes that Option Strict is off.) For example:

    Dim oDat As Object
    Console.Writeline(Year(sDat))       ' Displays 1
  • If datevalue is a date literal (a date delimited with the # symbol), the year must contain four digits.

Programming Tips and Gotchas

  • The validity of the date expression — and the position of the year element within the given date expression — is initially determined by the locale settings of the Windows system. However, some extra intelligence relating to two-digit year values (see the next item in this list) has been built into the Year function, which 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, it is much better programming practice to use — and require your clients to use — four-digit years.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata