Date Calculations Hours Difference

how do I calculate the number of hours between a date range?

The formula I am using works when the date is the same (10/6/20 7 am to 10/6/20 7 pm) I get 12, however, once I switch it to another date the calculation is wrong (10/6/20 8 am to 10/7/20 8 pm) I get 0.

I searched the forum and haven’t been able to find a clear answer on this. Please help.

Hi @jas2jamili,

It would be helpful to see the Bubble expression you’re using. It should literally be as simple as subtracting one date from another and then formatting the result in hours.


Premium Bubble Plug-Ins

Assuming your date range parameter name is “example_range”, it would go like this

example_range:end - example_range:start :format as hours

Be advised you used the term “range”, this is a reserved word. As there’s actually a Bubble datatype of “date range”, which I depicted. This would work however for any two arbitrary and unlinked date values.

1 Like

Yeah, good point. To expound a bit for anyone coming across this post, a date range is a span of time bounded by two dates - the start and end (which @anon38627393 referenced). Once you have 2 dates, finding the difference is just subtraction, and it’ll be either zero (exactly the same date), positive, or negative.


sorry for the late reply guys. It worked using the :format_as_hours logic (thank for your willingness to help. cool plugins)

1 Like