Hi,

I have an app that records times in military time in the format HH:MM. I am trying to calculate the response time between two times i.e.

txtDispatch.Text=12:00

txtArrival.Text = 12:15

How can I subtract 12:15 - 12:00 ?

I was trying to figure out how to create a method that removes the “:” and just calculate 1215 - 1200.

Or is there a way I can create a variable that says that 12:00 is a time?

You can do things like Dim d as date, but cannot Dim t as time.

If anyone has any ideas, I would certainly appreciate a little help.

Jim

Private Function TimeDiff(t1 as string, t2 as string) As integer

dim d1 as new date

d1.Hour = t1.NthField(":", 1).Val

d1.Minute = t1.NthField(":", 2).Val

dim d2 as new date(d1)

d2.Hour = t2.NthField(":", 1).Val

d2.Minute = t2.NthField(":", 2).Val

Return d2.TotalSeconds - d1.TotalSeconds

End Function

Thanks so much Joachim. I really appreciate the help. I used your code and adapted it to this method.

[code] Dim d1 as New Date

Dim t1 as String

Dim t2 as String

Dim X as double

t1=txtDispatch.Text

t2=txtArrival.Text

d1.hour = t1.NthField(":", 1).Val

d1.Minute = t1.NthField(":", 2).Val

dim d2 as new date(d1)

d2.Hour = t2.NthField(":", 1).Val

d2.Minute = t2.NthField(":", 2).Val

X= d2.TotalSeconds - d1.TotalSeconds

X=X/60

txtTime.Text=format(X, “0”)[/code]

Thanks again.

Jim

REM My code isn’t perfect, because i.e. “23:59” vs. “00:01” not handled.