Date / Time calculation runtime/duration between events

Hello AI2-friends,
I have been “tinkering” a function with the App Inventor for days now and am not able to reach my goal.
I want to calculate the running time in months, days, hours, minutes between two events.
Example:

  1. After pressing the “Start” button, the current date + time is saved in Tiny-DB Tag “x”.
  2. I press the “Stop” button later and the current date + time is saved in Tiny-Db Tag “y”.
  3. After pressing the “Calculate” button, I would like to display the running time of the event in months, days, hours, minutes and save it in Tiny-DB Tag “Z”.

Could someone give a tip on how I can best do this?

Did you do a search ? "duration"

You should find what you need in these two links

Hi and many thanks for reply,
a. in the the screen we have only a button (or a global-variabel) and not a datepicker or time-picker.
b. in the block of date-picker are not the hours and minutes we need for the duration-calculation.

Is that the right solution for me with the date picker?
Do you have an example APK, that I can convert myself?

Sorry, I’m still a beginner …but it’s a lot of fun with the AI2 :slight_smile:

It doesn’t matter where the date/time instants come from - clock, datepicker, the method for finding the duration between instants is the same

Hi again,
sorry, but i find not the mistake in my application.
The hours, minutes and seconds are not schown right (red-label):
grafik

Well, what you are returning for each time duration is “correct”, but you are getting the total shown for each one.

You will have to do some more work on the calculations to work out the days, then remove that amount, then the hours, remove that amount, then the minutes.

If you look at Taifun’s example in the link I provided above, he shows how to do this using milliseconds, and the quotient/remainder maths blocks

Try something like this:

1 Like

Hi…yes, i have modifyd the AIA from Taifun for my app …its work great !!!
Many Thanks and bye bye from Germany :slight_smile:

Danke Anke…:slight_smile: und Tschüss aus Bremen …

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.