Android Question DateUtils Calculate interval days in hours

Roberto P.

Well-Known Member
Licensed User
Longtime User
I'm using the management DateUtils.PeriodBetween to calculate the interval in hours between two dates. Shall not count the hours when you exceed one day, for example:

07/29/2015 - 10:00
30/07/2015 - 11:00

They are calculated 1 hour but not 25 hours

there is a way to properly calculate elapsed time?
thank you
 

DonManfred

Expert
Licensed User
Longtime User
25 hour is the proper value!
But you wann to Interpret IT in another way.
It is up to you to Do the rigth calculations...

Use parsedatetime and use only one date but the two Different Times to calculations the two values
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
B4X:
Dim OrigDateFormat As String = DateTime.dateFormat
DateTime.dateFormat = "MM/dd/yyyy HH:mm"
Dim p As Period
p = DateUtils.PeriodBetween(DateTime.DateParse("07/29/2015 10:00"),DateTime.DateParse("07/30/2015 11:00"))
Log(p.Days & " day(s) " & p.Hours & " hr(s)")  'displays 1 day 1 hr
DateTime.dateFormat =OrigDateFormat
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
Thank you for the answers, but probably will not make myself clear.

I need to calculate the number of hours that there are two periods of dates (with days apart) and I thought that the function PeriodBetween was able to do this calculation ElapsedTime

Thank You
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but probably will not make myself clear.
even after this post i for myself iĀ“m not sure to understand what exactly you want to do

@Mahares showed you the right way to calculate the period between two dates.

Maybe you should describe it more clearly what exactly is the base, what exactly do you want to archieve and what is the code you are trying to get this result but did not work
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
OK my friend....

this is a simple problem:

start time and date = 07.01.2015 10:00
end date and time = 07/25/2015 06:00

how many hours?

I thought that had already PeriodBetween function that returns the "sum of hours." While, returns the number of days and number of hours "part. In this case the hours are calculated -4.

I repeat, I thought there was the function elapsedtime.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
great Erel
This is exactly what I need. He must instantly code.
Thank You
 
Upvote 0
Top