The Date Data Type

A variable that contains date and time values should be declared with the Date data type.


Private today As Date

You can perform calculations on date/time values. Adding or subtracting integers adds or subtracts whole days; adding or subtracting fractions adds or subtracts fractions of days (expressed in hours and minutes). Thus, adding 20 adds 20 days, and subtracting 1/24 subtracts one hour.

You can use date/time literals in a macro by enclosing them within number signs (#), the same way you enclose string literals within double quotation marks. Visual Basic accepts a wide variety of date and time formats in literals. The following are all valid date/time values.


someDate = #3-6-93 13:20#
someDate = #March 27, 1993 1:20am#
someDate = #Apr-2-93#
someDate = #4 April 1993#

Date variables are initialized to 12:00:00 A.M. (midnight) on December 30, 1899. If you don't include a time in a date/time literal, Visual Basic sets the time part of the value to midnight (the beginning of the day). If you don't include a date in a date/time literal, Visual Basic sets the date part of the value to December 30, 1899. For more information about the various date/time functions and formats, see "Date" and "date formats" in Help.