Forum Academy Marketplace Showcase Pricing Features

Format date as days or as hours based on condition

Dear Bubble Forum Members,
I would like to format the result of a calculation as days if the “current date” - “comment creation date” > 1 day, and hours if it is less than or equal to 1 day.

In the image below, I would like to add something like: if (current date/time - Current cell’s post comment’s Creation Date) > 1 day:format as days, else format as hours, but that’s pseudo coding and Bubble is a no-code tool so that’s not working.
image

How can I achieve this? Any help or tips are highly appreciated!

I read this but could not find out how to format based on conditions.
Operators & Comparisons - Bubble Docs.

A possible workaround is to create two separate text elements, and format one as days and the other as hours. Then I would show one or the other based on a condition (whether days since comment is larger or smaller than 1). I feel that this workaround is tedious though.

Your thinking is correct… so you just need to add a conditional on the text element to achieve this…

i.e. have the main text set as current date/time - Current cell’s post comment’s Creation Date: formatted as Days

And a conditional:

When current date/time - Current cell’s post comment’s Creation Date: formatted as hours ≤ 24 change text to: current date/time - Current cell’s post comment’s Creation Date: formatted as Hours

1 Like

Works like a charm, thank you Adam!

1 Like

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