[Solved] Using +date operator within a conditional as opposed to use within a constraint?

Hi there,

New to Bubble - having done web dev of a LAMP stack many moons ago, Bubble is a delight!

Wondering if I could get some guidance…

Desired outcome: I’d like to display a list of things - Agreements between users. Each Agreement has an attribute [Expiry_Date]. When the expiry date is within a defined period (say a week) I wish to change the font colour to Red.

There is a helpful thread outlining the following logic:
If (Expiry_Date) > ((Current date and time)+(Days):7) then…

The +(Days) operator is available when used in a Search as a constraint. I cannot find the operator when trying to apply it within a conditional statement for an Element, in this case the text element displaying Expiry_Date for all of the things in the list.

Is this a ‘limitation’? If yes, then I won’t pursue. Or else, is there an alternative approach that could be taken here to achieve the desired outcome?

Appreciate any help/insight. Thanks!

The operator available is related to type. The operator is available in conditionnal the same way that you have in search. So if expiry date is a date field, the operator is available. However be sure to not use :formatted as on the date before the +days operator. Formatted as will turn the date into a string type. Can you share what you tried in editor conditionnal?

2 Likes

@Jici - thank you for your response and help.

Solved now.

I am not using ‘:formatted as’. I appreciated your call out that this changes type from date to string, as I didn’t know.

I tried applying the ‘+date:’ operator on the predicate (Expire_date + days: -7) and the operator is valid.

However, it wasn’t valid when trying to apply it to ‘Current Date/Time’.

I presume this is because Expiry_Date is a stored variable, so the + days: operator could be calculated on the stored variable, whereas ‘Current Date/Time’ is calculated at run time so therefore couldn’t be applied/calculated(?) - a guess, not sure.

Either way, screenshots below of the ‘solve’ to highlight ‘Expiry Date’ in red font when that date is less than 7 days away.


It should be available as an option, maybe some weirdness with doing subtraction before the date, I bet if you enable the parenthesis feature in the Versions tab it will become available

2 Likes

Go in settings and activate “parenthesis” feature in version tab
The reason why you don’t have it access is because the expression is no more a date but a boolean (read the whole expression in this case). With parenthesis feature, you should be able to add the +days directly to curent date and time and not to the whole expression

1 Like

@tylerboodman @Jici - thank you both. The Parenthesis feature solved it in the way I initially wanted to code the logic (see attached). I did not know you had to enable it/where it was located. Wish I could select both replies as the ‘solution’.

Screenshot 2024-04-13 at 8.30.34 pm

2 Likes

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