# Android Question[Solved]Difference between dates.

#### 73Challenger

##### Member
I've searched for a few hours and found quite a bit on date time differences but am not having any luck figuring out how to get the difference between 2 dates where i'm only concerned with hours and minutes. So my apologies for this in advance.

I'm not concerned with years, months and seconds, only hours and minutes.
I'd like to do the following for a work hours time calculation.
Hours allowed to work: 40 hours 0 minutes
Current Hours worked: 33 hours 12 minutes
Remaining hours left to work: 6 hours 48 minutes

I've seen several posts about using date time / period / date.Utils etc... but can't figure out how to get this result. I'd greatly appreciate any links and or thoughts on how I can accomplish this. Thank you!

Solution
thoughts on how I can accomplish this

This appears to be a simple arithmetic problem unless I did not grasp your intent:
B4X:
``Log(TimeDiff(40,0,33,12))``
B4X:
``````Sub TimeDiff(hallowed As Int, minutesallowed As Int, curh As Int, curminutes As Int) As String
Dim diff As Double = (hallowed*60+minutesallowed) -(curh*60+curminutes)
Return \$"\${Floor(diff/60)} hours \${(diff Mod 60)} minutes"\$
End Sub``````

#### Mahares

##### Expert
Longtime User
thoughts on how I can accomplish this

This appears to be a simple arithmetic problem unless I did not grasp your intent:
B4X:
``Log(TimeDiff(40,0,33,12))``
B4X:
``````Sub TimeDiff(hallowed As Int, minutesallowed As Int, curh As Int, curminutes As Int) As String
Dim diff As Double = (hallowed*60+minutesallowed) -(curh*60+curminutes)
Return \$"\${Floor(diff/60)} hours \${(diff Mod 60)} minutes"\$
End Sub``````

#### emexes

##### Expert
I've searched for a few hours and found quite a bit on date time differences but am not having any luck figuring out how to get the difference between 2 dates where i'm only concerned with hours and minutes.
I've seen several posts about using date time / period / date.Utils etc... but can't figure out how to get this result. I'd greatly appreciate any links and or thoughts on how I can accomplish this.

I would have thought that this post fits your mission perfectly, except that I've used a single number for time ie h.hhh rather than hh:mm:

https://www.b4x.com/android/forum/t...-in-pm-and-on-other-in-am.144377/#post-915342

If let me know where it runs off the track for your mission, I will happily adjust it accordingly for an additional 20% bonus fee.

#### 73Challenger

##### Member
@Mahares - Worked perfectly, thank you.
@emexes - Thank you for your response as well, It would have worked too.

Thanks again! The members in this community always come through!

Replies
97
Views
13K
Replies
4
Views
1K
Android Question Intervals between hours
Replies
4
Views
1K
Replies
3
Views
1K
Replies
105
Views
107K