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.

Posted on Mar 16, 2017 01:41 AM
Hi @LokeshH,
Please try the following

Find the number of months between two dates in C#

It might help you.

Cheers Andrea.