Android Question [Solved]Difference between dates.

73Challenger

Active Member
Licensed User
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
Licensed User
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
 
Upvote 1
Solution

emexes

Expert
Licensed User
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. ?
 
Upvote 1
Top