Number of hours from time difference between two dates

Hi @adamhholmes and @jonah.deleseleuc ,
Really appreciate your support. Yes, the countdown still dissapears.
I don’t know if the timer just dissapears or stops running, but when I go to the home page and then back to the page where the countdown should be, the timer is not there anymore, even though after booking immediately, it was there. I’m sure it has something to do with changing hte page and loosing the data for it.

And here is how I’m displaying this countdown on the page:

I don’t’ really understand what you’re saying, or what your doing in your screenshot with the end date (that doesn’t make much sense to me).

Maybe share a link to your page and editor so it’s clear what the issue is, what you’re trying to do, and where you’re going wrong.

Alright guys, I m getting closer. What am I doing wrong? It’s driving me crazy.
I think part of the problem was the countdown wasn’t loading dynamically at page load. I set another trigger for that. However, now the countdown doesn’ t show up most likely because there’s nothing in it (more below).

Please note the countdown documentation says we have to ADD “something” in end date. THat’s my understanding. If I add a number 5 let’s stay after :hours instead of booking_booked_hours, the formula works, and the countdown shows and starts, however it’s not dynamic. THat doesn’t help, I do need the dynamic formula.

The debugger says the end date is empty?! Is that because the formula is wrong and it can evaluate it?

I also tried what you suggested above, one current date - static date, and still doesn’t show up

I think this is being overcomplicated… @adig just so I get this straight:


You’re trying to get booking_hours_used which is being calculated by a booking's end date - booking's start date?

If so, you can just do exactly that booking's end date - booking's start date:formatted in hours


When you say:

What do you mean? What are you counting down to? I don’t really understand how a countdown plays a role here?


Edit: It looks like you’re counting down until the booking start date? If so, just reference the booking's start date then for Current date/time, if you want that to count in-real time, you need to create a custom state that’s something like “currentDateTime” that’s of type date. Then create a “Do every 1 second” action and set that state to the current date/time. Then in your countdown, for your Start Date, reference the custom state.

Hi @johnny ,

No, booking hours used willl be used whenever someone stops the booking(countdown). Let’s leave that aside for now.

To start with, I just want a countdown that shows the number of hours and minutes left from that booking which is based on the variable called number_of_hours_booked (number in the database, between 1-8hrs) and the booking’s date start. Or Vice versa. I’m also confused by how the countdown works.

Thanks for the suggestion with the state, but surely it can be done easier.

What is number of hours booked? Why is it a variable?

Edit:

Like Current Date - Booking Start?

Number of hours booked is how many hours the user paid for. it’s like a credit for a booking.
I tried current date - booking start and it doesn’t work. see above in the last picture.

How many hours the user paid for?..

Just so I have the full picture, what are you trying to accomplish? Just based off trying to piece together what’s been said already, you have:

  • A booking start date
  • A booking end date

What do you want the number of hours booked for? Regardless, you can easily compute that by doing Booking Start Date - Booking End Date.

Hi Johnny,

I do not have a booking end date. I have number of hours booked. Number of hours is the credit the user has.
The countdown is supposed to show how many hours and minutes are left from his booking from the total credit (in hours). It’s a simple concept.

Ok this is more clear.

This is what you should do:

  • Create a custom state that stores the current date/time as i described above

Then compute the expression:
Custom state current date/time - (booking start +hours: number of hours) :formatted in hours

Then do the same for minutes.


The reason why your countdown above wasn’t counting down is because when you reference “Current date/time,” it’s only the current date/time when the page loads, it doesn’t continue to update – that’s why you do it with a custom state that updates the time every second.

2 Likes

Thanks bud!! @johnny So where do I put this compuation? in the end date of the counter or in the custom state value?. RIght now, im puttin this calculation in the value of that custom state, but I don’t have the options +hours

You should create a custom state called currentDateTime or whatever you want, then create a Do every 1 second action in workflow that has one step which is setting that state to the Current date/time.

Then you can use the expression:

Custom state current date/time - (booking start +hours: number of hours) :formatted in hours in a text field. No need for a plugin…

1 Like

Thanks a lot Johnny! almost there. The number doesn’t look right but it seems it refreshes.
here is how it looks now and the expression i Have in the text field

and the calculation

Your custom states for the booking times might be wrong. How are you setting those? Why don’t you reference it from the database directly?

all of them except the one you mentioned “currentDateTime” (which is set as current date time in the state) are in the database. booking_start_timne is date type and booked_hours is number in the DB

They look like there’s referencing a custom state

Sorry, I don’t understand what you mean. I though currentDateTIme HAD to be a state where i set “current date time”

How are these values computed?

Also – my bad. I’m realizing it the expression should be:

(Booking start +hours: booking hours) - CurrentDateTime:formatted as hours

1 Like

They’re not. they’re literally either dates or numbers. They are coming from the DB. Values and format are correct there. I checked. Booking’s (all) is a group with type of content “booking”

1 Like

Ok, how are those values stored in the database? It’s hard to get the full picture with only glimpses of your app.