Wednesday 5 December 2012

Difference between two DateTimes VB.NET


Difference between two DateTimes VB.NET

  • One date is  less than two date  all values will be negative
  • one date is equal and only time diff, total hours,mins,sec will have values
  • One date is greater than two date all values will be positive

Public Function GetTimedifference(ByVal one As DateTime, ByVal two As DateTime) As Integer
          If DateTime.Compare(one,two) <= 0 Then
              Dim tspan As TimeSpan =  one.Subtract(two) 
              Console.WriteLine(tspan.TotalDays)
              Console.WriteLine(tspan.TotalHours)
              Console.WriteLine(tspan.TotalMinutes)
              Console.WriteLine(tspan.TotalSeconds)
              Console.WriteLine(tspan.TotalMilliseconds)
          End If
          Return 1
End Function


No comments:

Post a Comment