Home |
Search |
Today's Posts |
#17
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Peter T" <peter_t@discussions schrieb im Newsbeitrag
... "Helmut Meukel" wrote in message ... That inaccuracy is an issue of the VBA function, not the data type. You can still declare your variable as Date and get the higher accuracy: dim x as Date x = [now()] That's *if* you use the spreadsheet function. The VBA date data type is internally a double and can therefore contain values with fractions of seconds. I didn't refer to VBA's function. I agree the Date data-type can handle a much larger range of values than I implied, though it can't handle the range of a Double or even a Long (with large +/- values) Regards, Peter T Peter, Here is the official statement from Microsoft: | Microsoft Office XP Developer | | The Date Data Type | | Microsoft® Visual Basic® for Applications (VBA) provides the | Date data type to store date and time values. The Date data type | is an 8-byte floating-point value, so internally it is the same as the | Double data type. The Date data type can store dates between | January 1, 100, and January 1, 9999. | | VBA stores the date value in the integer portion of the Date data | type, and the time value in the decimal portion. The integer portion | represents the number of days since December 30, 1899, which | is the starting point for the Date data type. Any dates before this | one are stored as negative numbers; all dates after are stored as | positive values. If you convert a date value representing December | 30, 1899, to a double, you'll find that this date is represented by | zero. | | The decimal portion of a date represents the amount of time that | has passed since midnight. For example, if the decimal portion of | a date value is .75, three-quarters of the day has passed, and the | time is now 6 P.M. | | Because the integer portion of a date represents number of days, | you can add and subtract days from one date to get another date. | As stated, dates before December 30, 1899 are negative values. The stated limitations are due to the conversion routines used by VB/VBA to transform a date string into the internal representation (a double). For conveniance, you can enter a two-digit year and it's expanded to a four-digit year. This prevents you from entering dates before January 1, 100. These conversion routines are also limited to positive year values, they can't handle years like 333 B.C. And they can't handle 5-digit years. BTW, the upper limit is wrong, a Date variable *can* store 12/31/9999. Try it! To avoid problems with years outside the limits, VB/VBA even throws a "runtime error 6" if you try to add or subtract a value that would give a result outside of the limits. So, yes, the range is artifically limited but *not* the accuracy, the resolution. Here the Date data type is identical to the Double. And the original problem was resolution (fractions of seconds). Using a Double would gain nothing. Helmut. |