Search notes:

VBA: data type date

A date literal allows to «hard code» a specific date/time unambigously, that is independent from the currently used locale.
A (variable) date (without time) can be constructed from three integer-variables with dateSerial(year, month, day).
Similarly, timeSerial(hr, min, sec) constructs a time.
The functions now returns the current date and time, date just returns the current date.
format can be used to convert a date into a string.
Using year(), month(), day(), hour(), minute() and second() to extract the respective parts of a date as integer.
Date arithmetic is possible with dateAdd(…) and dateDiff(…).
These functions add a given number of days to a date or return the number of days between two given days, respectively
Internally, a date is stored as double. the decimal places store the time fraction of a day and the non-decimal places the days since a given date.
The default value for a date is 1899-12-30 00:00:00.
cDate is a conversion function that converts the input parameter to da date.

Internal representation

VBA stores a date as a (8 byte) IEEE-754 floating point value (as is also a double).
The value 0.0 corresponds to midnight (start of) December 30th, 1899:
? format(cDate(0.0), "yyyy-mm-dd hh:nn:ss")
1899-12-30 00:00:00
? format(cDate(0.0 + 1.0/86400), "yyyy-mm-dd hh:nn:ss")
1899-12-30 00:00:01
? format(cDate(1.0), "yyyy-mm-dd hh:nn:ss")
1899-12-31 00:00:00

See also

datatypes

Index