Count Days using 2 Air Date/Time Picker?

Good Day,

just want to know how can i count days using 2 Air Date/Time Picker?

example

i have a Group Container (Reservation) inside that container i have 2 Air Date/Time Picker
Air Date/Time Picker A
Air Date/Time Picker B

below that 2 air date/time picker A&B i added an Input Form (Counted Days) to display the count days

so when i choose a date on Air Date/Time Picker A = July 1 and on Air Date/Time Picker B = July 31

how can i display the total Day Count of that 2 Date/Time Picker on a Input Form(Counted Days) as Initial Content?

so the Initial Content is = 30 or 31

Hi @jigsgfx.gj,
Calling Air Date/Time Picker’s value returns a date. Therefore you can use the built-in date operations on this value.
To get the difference between two dates you can use the minus ( - ) operation (https://bubble.io/reference#Data.Messages.date.minus) and then display the result in the format you want (e.g. days, hours, minutes, seconds).
For your specific case you can use the following expression for the Initial content of your Input Form( Counted Days)
AirDate/TimePicker B’s value - AirDate/TimePicker A’s value:format as days
You may have to switch A or B depending on which is earlier else you may end up with negative values.

Important things to note:

  1. AirDate/Time picker value (date) contains a time component.
  2. The dates minus (-) operation takes into account the time ( up to a millisecond i guess). This means that it is possible to have values with decimal points in your case. E.g You may end up with something like 2.5, meaning 2 and half days.
  3. If you have an Air Date/Time picker and you don’t select time, the time will be set to 00:00:00. If you’re not interested in having partial days, you will have to make sure all the times are 00:00:00.
    Alternatively set the Content Format for your Input field to Decimal. Then depending on whether you want to round up or down you use the :floor or :ceil operation respectively on the date subtraction expression above
  4. It is important to note that if you use the Today button to pick a date the current time will be selected.
    As an example select today’s date from the picker for one of your Air Date/Picker and use the Today button to select today’s date for the second picker. If you do the subtraction you will get some decimal value less that 1. e.g 0.5 if the current time is about 12noon. This is because choosing today’s date from the picker will set the time to 00:00:00. And since we’re assuming current time is about 12noon the time will be set to 12:00:00. And the subtraction 12:00:00 - 00:00:00 will give us 12 hours which is half day (0.5).

Sorry for the long explanation. I developed the Air Date/Time picker so wanted to use this opportunity to explain this in detail in case someone else have a similar question.
I assume the default date/time picker behaves the same way too (haven’t tried though).

Happy bubbling.

1 Like

@seanhoots hank you for your answer, but how can i make it not to have negative values? can i still be able to count that value even it’s negative?

follow up on this one specially @seanhoots

Just ensure that the the picker with the earlier date is the second one in your expression.
e.g. If picker A contains start date and picker B contains end date, then your expression should be B - A

great it works thanks alot

This topic was automatically closed after 70 days. New replies are no longer allowed.