Date (data type)

Syntax

Date

Description

A data type capable of holding date and time values.

Comments

Date variables are used to hold dates within the following range:

  January 1, 100 00:00:00 <= date <= December 31, 9999 23:59:59

  –6574340 <= date <= 2958465.99998843

Internally, dates are stored as 8-byte IEEE double values. The integer part holds the number of days since December 31, 1899, and the fractional part holds the number of seconds as a fraction of the day. For example, the number 32874.5 represents January 1, 1990 at 12:00:00.

When appearing within a structure, dates require 8 bytes of storage. Similarly, when used with binary or random files, 8 bytes of storage are required.

There is no type-declaration character for Date.

 

Date variables that haven't been assigned are given an initial value of 0 (i.e., December 31, 1899).

 

Date Literals

Literal dates are specified using number signs, as shown below:

  Dim d As Date
  d = #January 1, 1990#

The interpretation of the date string (i.e., January 1, 1990 in the above example) occurs at runtime, using the current country settings. This is a problem when interpreting dates such as 1/2/1990. If the date format is M/D/Y, then this date is January 2, 1990. If the date format is D/M/Y, then this date is February 1, 1990. To remove any ambiguity when interpreting dates, use the universal date format:

 date_variable = #YY/MM/DD HH:MM:SS#

The following example specifies the date June 3, 1965 using the universal date format:

  Dim d As Date
  d = #1965/6/3 10:23:45#

See Also

Currency (data type); Double (data type); Integer (data type); Long (data type); Object (data type); Single (data type); String (data type); Variant (data type); Boolean (data type); DefType (statement); CDate, CVDate (functions).

More information

D