Date-calculation with firebase

Hi there

I am not a programmer and started with building my first app. What the app is doing currently: saving and collecting hotel-nights in firebase.

I am able to display, edit and delete data so far, but I have no knowledge on how to handle the json differently than displaying the data.

How, for example could I calculate “checkout-date” - “checkindate” and display thus the nunber of nights I stayed in the hotel? So far I save the values as a string.

Thanks
Andreas

1 Like

In your firebase DB you should save the dates as “timestampValue”. When fetching the data into the app, stores the states in a date variable. You can get difference in days, by using the formula DATETIME_DIFFERENCE formula in appGyver.

Note that if you want to save in string format to firebase, you could convert it to datetime variable on your app, however, that’s not the proper saying managing dates.

Check out the reference doc for calculating dates with appgyver: https://docs.appgyver.com/reference/formula_functions/date/datetime_difference

1 Like

Hi @Alan_Alves

Thanks for your help. Additional question in regard to the visibility of the time which I need to send too. How can I hide the time part of the timestampValue in such a way that it is not displayed?

Thanks
Andreas

1 Like

@Alan_Alves thanks a lot, that helps. And last question (I feel stupid to ask but I wasn’t successful with the search function).

With the

DATETIME_DIFFERENCE(“pageVars.checkindate”, “pageVars.checkoutdate”)

I have now the “problem” that it is now stored in timestampValue and not a string. How can I convert it?

1 Like

You convert it to string with FORMAT_DATETIME_LOCAL:

FORMAT_DATETIME_LOCAL(DATETIME_DIFFERENCE(pageVars.checkindate, pageVars.checkoutdate), “MM-DD-YYYY”)

1 Like