开发者

convert date to date serial

开发者 https://www.devze.com 2023-03-17 15:41 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号