Calculate number of months between two dates in VB.Net

Last Reply on Mar 16, 2017 01:56 AM By LokeshH

Posted on Mar 16, 2017 01:41 AM

Hi.

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 on Mar 16, 2017 01:56 AM.
Posted on Mar 16, 2017 01:56 AM

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