Years Between Dates : Date Time Function « Date Time « VB.Net






Years Between Dates

   
Public Class MainClass
    Public Function YearsBetweenDates(ByVal StartDate As DateTime, ByVal EndDate As DateTime) As Integer
        If Month(EndDate) < Month(StartDate) Or (Month(EndDate) = Month(StartDate) And(EndDate.Day) < (StartDate.Day)) Then
            Return Year(EndDate) - Year(StartDate) - 1
        Else
            Return Year(EndDate) - Year(StartDate)
        End If
    End Function

End Class

   
    
    
  








Related examples in the same category

1.Date Time related FunctionDate Time related Function
2.Next Working Day
3.Parse(String) method returns a DateTime value whose Kind property is DateTimeKind..::.Unspecified
4.Parse(String) parses date and time values using the formatting conventions of the en-US culture
5.Generic and nongeneric versions of the CompareTo method for DateTime value