Vba convert date to value
Get via App Store Read this post in our app!
VBA Date as integer
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() .
To get the integer part, use
which would return a LongDouble with no decimal places (i.e. what Floor() would do in other languages).
Using CLng() or Round() would result in rounding, which will return a "day in the future" when called after 12:00 noon, so don't do that.
Just use CLng(Date) .
Note that you need to use Long not Integer for this as the value for the current date is > 32767
You can use bellow code example for date string like mdate and Now() like toDay, you can also calculate deference between both date like Aging
NB: Used CDate for convert Date String to Valid Date