VB.NET DateSpan Class

Tired of writing code to find the years and months between two dates?

”’ <summary>

”’ Provides an easy way to get the number if years and months bewteen two dates.

”’ </summary>

”’ <remarks></remarks>

Public Class DateSpan

   Dim _Years As Integer

   Dim _Months As Integer

 

 

   Public Sub New(ByVal StartDate As Date, ByVal EndDate As Date)

 

      Dim intTotalMonths As Integer = DateDiff(DateInterval.Month, StartDate, EndDate)

 

      _Years = intTotalMonths \ 12

      _Months = intTotalMonths – (_Years * 12)

   End Sub

 

   Public ReadOnly Property Years() As Integer

      Get

         Return _Years

      End Get

   End Property

 

 

   Public ReadOnly Property Months() As Integer

      Get

         Return _Months

      End Get

   End Property

 

End Class

Leave a Reply

Your email address will not be published. Required fields are marked *