How to do math on dates?

I want to do the following:

User clicks a button to start a task - App records the timestamp in the background (date & time) - DONE
User clicks a button to finish a task - App records the timestamp in the background (date & time) - DONE

A modal pops up only if the time between these two timestamps is greater than 90 minutes.

But I can’t figure out how to do math on dates in the options…

Any suggestions?

Hi @naossoan ,
You can use a hack for this. Since any number divided by a smaller number will be a fractional number (Like 100/90 gives 1.XX), and the other way around gives “0.XXX”.By default any divisional will be “0.XXXXX” or “N.XXX” represented as decimals and so on.

A day has 24 hours which represents 1440 Minutes

If you add an Input text field with “Number” format and add the “Current Time” for example, you will get something similar to:

Adalo Backend

Adalo Frontend

image

Now current time is represented in numbers format (For this purpose we use 80 minutes which is smaller than 90 minutes)

If you now add another Input text field with “Number” format and apply custom formula like this:

(This is where you would have the Last Timestamp - First Timestamp)

We are saying to the current date/time sum (80/1440) so this calculation will add the 80 minutes to the current time, then in the second part we subtract the current time, so we are making the different between 2 dates in “Date/time/day” format, we get this:

image

Now if you multiply this by 1440 (Number of minutes in a day), you get, yes you are right, 80 Minutes give and take

image

So to achieve what you need, you need to get the difference of days (In this case 0.055555555554747116), multiply by the 1440 Minutes, and you get the current difference.

Now if we divide 90 by a higher number you would always get “0.XX”, if you divide by a lower number, you would get at least “1.XX”

image

image

So if you want to send to the Modal, only if difference is higher than 90 minutes, you apply condition in the button “Sometimes…” if the difference of the dates calculated “Contains” the expression "0."

And if you would like to use smaller instead of higher, you would reverse the calculations like this:

image

image

Which you would still use the conditional "0.XX"

Hope this is helpful, if complicated let me know.

Have fun Adaloing :slight_smile: .

This seems really confusing but I will try it. I also don’t want any of this stuff showing on screen or being able to be interacted with by the user in any way shape or form so adding inputs to the screen is going to be a problem.

I will check it out though. Thank you!

I’m also having a really hard time figuring out how to make a multi-step process that updates a single “booking” at each step, and being able to save the progress of the user in case they close the app, or get disconnected or something like that.

But it appears as though if I have more than 1 screen linking data to another screen, the data link breaks, so I’m not sure how to get around that.

I tried doing something like creating a “counter” field which is just a number. On each screen load, it increases the counter. Then if the user somehow closes the app and reopens, as it goes to their home screen which is how adalo inherently works, I went them to be able to go back to the page they were at before in the process without going through any of the previously completed screens because there are timestamps happening in the background and I do not want them to be changed or updated after the fact.

So on the home page when the user clicks continue it will go to step 1, 2, 3, whatever, depending on the value of the counter…but since step links to each next step, linking to the steps from the home page seems to break the data links and I don’t understand how to get around that.

Hi @naossoan ,

Use Make list to any element, such as button, set the collection to be the same as previous screens that is to the screen you want to link to.

To continue to the previous step, use conditional in link action at the redirect screen, this is new screen that replace your home page.

For date time calculation, it is actually a number with long tail of fraction, consider playing them by multiplying 60 or 24, and some old posts have solved this.

I’m not sure, but this does not sound like what I want to do.

I don’t want there to be a “redirect” page. I want the user to login and go to their bookings page, which already happens. This technically uses a blank ‘redirect’ page already as it is used to check the role of the user who logged in, then redirects them to the appropriate screen based on their role.

There, they see a list of bookings assigned to them. When they click on the booking, if they have not yet done anything with it, it will go to the first step in the process.

If they have interacted with it before but for some reason closed the app or whatever, and need to continue, I want it to go to where they were before, not to the first step in the process as it will break the entire workflow.

As mentioned, I was able to accomplish this by using a number system where when the screen associated with each step of the process loads, it would set the number to 1, 2, 3, etc. Then when they clicked their booking it would go to the appropriate page based on the number.

However, the button on the page the user clicks when they are done these tasks which updates the booking and links to the next screen, with the “current booking” data, it would give me a notice saying that it will make the “current booking” data unavailable on that next screen.

Why, I don’t know or understand how but I need that data on every stage of the process…

I got rid of all the logic that tracks where the user was in the process, and now each of the buttons works properly to take them to the next screen…but I need to add that all back in somehow.

Will have to keep experimenting…

Well, I would say Adalo can do this, but since it is visual programming by default, and by articulating issue like this in text, it would be more difficult to solve.

All the features are here, make list, conditional link, redirect home screen, logged in user fields, probably others, all these can be ingredients of your experiments.

Hi @naossoan ,
This was just a tutorial how dates and calculations would work for your exercise. Maybe too much for first explanation :smiley:

In this case: I created 2 collections:

  1. Task
    When you click on the “+” symbol it will create a task in the collection “mytask” with the task name and the start date (Will be current time for this exercise)

image

  1. MyTask
    This contains startdate and enddate

When you created previously the task, now this task appears in your “Mytask” collection, if you click on it, it will go to another screen to show the details of that task

As you can see task below was created 27 minutes ago

Details Page

image

8:42 with the 9:09 around 27 minutes

In the button “Complete Task”, if I click it, it will update the current task with the Current Time (Assuming when we complete, it is in that exact moment), so current difference in completing is 27 minutes.

Then in the input field I have “3.2XXX”. this is the calculation I was explaining before:

image

90 Minutes / ((End Date - Start Date) x 1440 )

1440 Minutes is 24 Hours, so 1 Day, this is to convert difference to minutes from days

Then because 27 minutes is smaller than 90, it will be always “N.XX” (i.e. 3.2471…)´, if it would be bigger, it would be “0.XXX”

Example:

90/27 = 3.2XXX
90/100 = 0.XXX

I apply that condition in the button as a 2nd action: to link to modal if the calculated field contains “0.XX”, so any number higher than 90 minutes.

The calculated field you can hide from the user by going into the screen

I hope it now makes more sense

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