Calculate number of months between two dates in VB.Net

Last Reply one year ago By LokeshH

Posted one year ago


I want to calculate number of months between two dates.

I have used the below code but it's showing Month=0.

Dim d1 As DateTime = New DateTime(20171, 3)
Dim d2 As DateTime = New DateTime(2017, 31, 3)
Dim As Integer = Math.Abs((d1.Year - d2.Year))
Dim months As Integer = ((M * 12)  + Math.Abs((d1.Month - d2.Month)))

Please suggest any othe code.


Thank you.

You are viewing reply posted by: LokeshH one year ago.
Posted one year ago

Thank you Sir, after logn time a got the answer. Thank you so much.