acdagirl
asked on
how do I calculate time taken between two Datetime's
Given the following, how do I calculate the time difference between timeLineStart and timeLineEnd - or is there a better way than I've tried below?
Dim timeLineStart As DateTime
Dim timeLineEnd As DateTime
Dim timeTaken As DateTime
timeLineStart = System.DateTime.Now
(run a stored procedure....)
timeLineEnd=System.DateTim e.Now
timeTaken = ?? (in minutes)
Dim timeLineStart As DateTime
Dim timeLineEnd As DateTime
Dim timeTaken As DateTime
timeLineStart = System.DateTime.Now
(run a stored procedure....)
timeLineEnd=System.DateTim
timeTaken = ?? (in minutes)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim timeTaken As TimeSpan = DateTime.Now.Subtract(time
Now you can get the individual parts such as Hours, Minutes, Seconds, etc. if you need them:
Debug.Print(timeTaken.Hour
Debug.Print(timeTaken.Minu
Debug.Print(timeTaken.Seco
These give you the WHOLE parts whereas the TotalXXX() properties give you fractional values.
For instance, if it took 84 minutes:
Hours = 1
Minutes = 24
but:
TotalHours = 1.4
TotalMinutes = 84
See the TimeSpan class:
http://msdn2.microsoft.com/en-us/library/system.timespan_members.aspx