convert date to date serial
I'm trying to convert a date (date type) into a long. This long should be something like the number of days since the 1 January 1900. How to get this in VBA ? In excel I'm gettin开发者_开发知识库g this automatically when i concatenate a date with a string.
Function dateToLong(ByVal d As Date) As Long
dateToLong = CLng(d)
End Function
If you need to capture the time in the long use this:
Function Dt2Lng(aDate As Date) As Long
'-- acept datetime range from MinDate to
'-- (MinDate + 49710 days + 6:28:15) ~ 136 years
Dt2Lng = CLng((aDate - MinDate) * 86400 - 2 ^ 31)
End Function
Say if you have "1/1/2016" in A1, you could use Range("A1").Value2 to get the date serial number.
精彩评论