is there a way to get the underlying integer for Date function in VBA ? I’m referring to the integer stored by Excel to describe dates in memory in terms of number of days (when time is included it can be a float then I guess). I’m only interest in the integer part though. Is there just another function for that ?
For example, for today() I’d like to be able to get back 40877..
Date is not an Integer in VB(A), it is a Double.
You can get a Date’s value by passing it to
CDbl().From the documentation:
So in the 1900 system,
40877.805...represents 40,876 days after January 1, 1900 (29 November 2011), and ~80.5% of one day (~19:19h). There is a setting for 1904-based system in Excel, numbers will be off when this is in use (that’s a per-workbook setting).To get the integer part, use
which would return a
LongDouble with no decimal places (i.e. whatFloor()would do in other languages).Using
CLng()orRound()would result in rounding, which will return a “day in the future” when called after 12:00 noon, so don’t do that.