Your Products have been synced, click here to refresh
A datetime is in fact a double, with the date in the integer part and the time in the decimals. So, you just convert your dates to double and do the subtraction, and you will get the number of days (and fractions of days) between the two:
Sub Main d1 = cdbl(dateserial(2015, 2, 1)) d2 = cdbl(dateserial(2015, 3, 1)) MsgBox d2-d1 End Sub
gives the answer 28, while
Sub Main d1 = cdbl(dateserial(2016, 2, 1)) d2 = cdbl(dateserial(2016, 3, 1)) MsgBox d2-d1 End Sub
gives 29, so it seems leap years are also handled.
A datetime is in fact a double, with the date in the integer part and the time in the decimals. So, you just convert your dates to double and do the subtraction, and you will get the number of days (and fractions of days) between the two:
Sub Main d1 = cdbl(dateserial(2015, 2, 1)) d2 = cdbl(dateserial(2015, 3, 1)) MsgBox d2-d1 End Sub
gives the answer 28, while
Sub Main d1 = cdbl(dateserial(2016, 2, 1)) d2 = cdbl(dateserial(2016, 3, 1)) MsgBox d2-d1 End Sub
gives 29, so it seems leap years are also handled.
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |