Subtracting time?

Netnoobie

Regular
Joined
Feb 6, 2003
Messages
94
Location
Philadelphia
Hello all.

I'm looking to get a rate based on a number and time spent. For time spent I need to subract a start time and an end time. I can't seem to find anything that will allow me to subract the times. The format for the two time is 'hh:mm:ss AM'. How can I subtract time in ASP.NET?

In the end I need to get something like:
iRate = iRecords / (timeStart - timeEnd)

Anyway, many thanks for anyone who can shed some light on this for me.
 
Actually in the table the format for the Times is yyyy/mm/dd hh:mm:ss AM. So this line:
Dim datOut As TimeSpan = CDate(strTimeOut).Subtract(CDate(strTimeIn))

Gives me:
Cast from string "20030303 10:11:18 AM" to type 'Date' is not valid.

So obviously the format to start with is wrong or something. Any thoughts?
 
Netnoobie:
What about the "DateDiff" function? Basically, you feed it how you want the difference to come back (hours, minutes, etc.), the first date, and then the second date. It calculates the difference for you. You said that the table you're working with has the datetime in the format "yyyy/mm/dd hh:mm:ss AM". I believe that function will work with that format. The DateDiff function is actually overloaded so that it will either accept two dates entered or two datetimes. Give that a try and see if it helps.
 
Back
Top