# Subtracting time

#### walterf25

##### Expert
Longtime User
Hello all, can anyone please help me by teaching me how to subtract two different time, let's say i start something at 10:05 and it finishes at 10:15, how can i subtract this two times? anyone?

thanks,
Walter

#### NJDude

##### Expert
Longtime User
You will have to save the TICKS (convert the time to ticks) then substract.

#### walterf25

##### Expert
Longtime User
subtract time

yeah i thought so, argh, just wondering if there was already a function that did it!

thank you sir,
Walter

#### Mahares

##### Expert
Longtime User
Will this do it for you?

B4X:
``````Dim DateStart, DateEnd, TimeDiff As Long
DateStart = DateTime.DateParse("05/11/2012") + DateTime.TimeParse("10:05:00 AM")
DateEnd = DateTime.DateParse("05/11/2012") + DateTime.TimeParse("10:15:00 AM")
TimeDiff = DateEnd - DateStart
Msgbox(TimeDiff/1000/60,"Elapsed Minutes")``````

#### NJDude

##### Expert
Longtime User
If I may enhance the code provided by Mahares, I converted it to a function:
B4X:
``````Sub GetDifference(dDateStart As String, dTimeStart As String, dDateEnd As String, dTimeEnd As String) As Double

Dim DateStart, DateEnd, TimeDiff As Long

DateStart = DateTime.DateParse(dDateStart) + DateTime.TimeParse(dTimeStart)
DateEnd = DateTime.DateParse(dDateEnd) + DateTime.TimeParse(dTimeEnd)

TimeDiff = DateEnd - DateStart

Return TimeDiff / 1000 / 60

End Sub``````

So you can call it like this:
B4X:
``````X = GetDifference("05/11/2012", "10:05:00 AM", "05/11/2012", "10:15:00 AM")

Msgbox("Minutes=" & X, "Result")``````

Android Question Time subtractions
Replies
7
Views
1K
Replies
5
Views
1K
Replies
5
Views
3K
Android Question Problem subtracting times
Replies
5
Views
1K
Replies
1
Views
867