Year Function

See Also1ZQ4C6T              Example3Z7EFW>Low

Returns an integer between 100 and 9999, inclusive, that represents the year of a date argument.




The dateexpression part of the syntax is any numeric expression71RISN or string expression1330R89 that can represent a date and/or time from January 1, 100 through December 31, 9999, where January 1, 1900 is 2.  Numbers to the left of the decimal point in dateexpression represent the date; numbers to the right represent the time.  Negative numbers represent dates prior to December 30, 1899.

If dateexpression is Null1DDW7C0, this function returns a Null.

See Also

Date, Date$ Functions3E3X9E

Date, Date$ Statements3E3X9R

Day FunctionLANDAY

Hour FunctionGU67IG

Minute Function5OWKHCJ

Month Function3NARHG

Now FunctionLANNOW

Second FunctionC46EYJ

Weekday FunctionM393JM

Year Function Example

The example uses the Year function to determine whether or not the current year is a leap year.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim CurYear, LeapYear, Msg               ' Declare variables.

   CurYear = Year(Now)                      ' Get current year.

   If CurYear Mod 4 = 0 And CurYear Mod 100 = 0 Then

      If CurYear Mod 400 = 0 Then           ' Evenly divisible by 400?

         LeapYear = "is a leap year."

      Else                                  ' Not evenly divisible.

         LeapYear = "is a centesimal year but not a leap year."

      End If

   ElseIf CurYear Mod 4 = 0 Then

      LeapYear = "is a leap year."


      LeapYear = "is not a leap year."

   End If

   MsgBox "The current year, " & CurYear & ", " & LeapYear

End Sub