Hi Ronald
Date Data Type
Date variables are stored as IEEE 64-bit (8-byte) floating-point
numbers...
Certainly, it is documented that they are stored in double-floating numbers,
but what is *not* documented (to my knowledge) is the relationship between
that number and actual dates, nor the slightly unexpected behaviour which
occurs when the number goes negative.
It is a popular misconception (I have publicly stated it myself) that the
numeric value represents the number of whole days and fractions of a day
after *or before* "Time Zero" (30-Dec-1899 00:00). This is not the case,
which explains why a subtraction over that boundary time does not work.
In actual fact, the integer part of that number is the number of midnights
before or since "Time Zero" and the fraction part is the fraction of a day
*after* that time. Try the following:
?format(cdate(#30-Dec-1899 00:00# - #3:00#), "dd-mmm-yyyy hh:nn")
Perhaps the expected result is 29-Dec-1899 21:00 (three hours before
midnight) but in actual fact you get
30-Dec-1899 03:00.
This is because the subtraction gives a numeric result of -0.125. This is
interpreted as:
Day = -0 = 0 = 30-Dec-1899
Time = 0.125 (not -0.125) = 1/8 of a day = 3 hours = 03:00
The alternative:
?format(DateAdd("h", -3, #30-Dec-1899#), "dd-mmm-yyyy hh:nn")
gives the correct result.
Actually, Excel and all other MS Office applications use the same common
data types which is found under the drill down topics of:
VBA in Excel does, but not Excel itself. From the Excel 2003 help:
------- Start quote ------
Excel supports two date systems: the 1900 and 1904 date systems. The default
date system for Microsoft Excel for Windows is 1900. The default date system
for Microsoft Excel for the Macintosh is 1904. You can change the date
system. On the Tools menu, click Options, click the Calculation tab, and
then select or clear the 1904 date system check box.
The date system is changed automatically when you open a document from
another platform. For example, if you are working in Excel for Windows and
you open a document created in Excel for the Macintosh, the 1904 date system
check box is selected automatically.
The following table shows the first date and the last date for each date
system and the serial value associated with each date.
Date system First date Last date
1900 January 1, 1900 December 31, 9999
(serial value 1) (serial value 2958465)
1904 January 2, 1904 December 31, 9999
(serial value 1) (serial value 2957003)
-------- End quote ---------------
This means that the date *number* for 1-Jan-1900 in Excel for Windows is 1,
while in Access (and VBA) it is 2. This discrepancy disappears after
1-Mar-1900 because Excel erroneously treats 1900 as a leap year (try
=DateValue("29-Feb-1900") in an Excel worksheet.)
My whole point is that if you use the date/time manipulation functions that
are provided, you will always get the expected result. Results from
fiddling "under the hood" must be treated with caution. That said, it would
be nice if DateAdd and DateDiff recognised the existence of fractions