LilBrown
LilBrown

Reputation: 11

How To Subtract two times

Hi guys

i searched so much for this but no result so i need help!!

I have two times those are in this form ("hh:mm")

like this ex:

15:20 - 12:10 = 03:10

but in other form of variables because the times are not static and saved in SQL DB

i don't know what variable those should be string or dateandtime

a = dr!t_in
b = dr!t_out
msgbox(a-b) 'this shows the answer 

many tanks

Upvotes: 0

Views: 512

Answers (2)

OneFineDay
OneFineDay

Reputation: 9024

Another way using the TimeSpan class.

Dim timeIn As String = "12:10"
Dim timeOut As String = "15:20"
MessageBox.Show(TimeSpan.Parse(timeOut).Subtract(TimeSpan.Parse(timeIn)).ToString(("hh\:mm")))

Upvotes: 1

raumkrieger
raumkrieger

Reputation: 262

Check out the DateTime object, and specifically the Subtraction operator. You'll have to convert the times into DateTime objects first, which is fairly straightforward.

Upvotes: 1

Related Questions