Hi Team,

Is it possible to subtract number of days in a similar fashion to using +(days): to add number of days to a Date?

thank yoju

Hi Team,

Is it possible to subtract number of days in a similar fashion to using +(days): to add number of days to a Date?

thank yoju

Yes, you can use the +day and use a negative number

5 Likes

Hi Emmanuel,

I have a similar issue:

I get a positive integer from an input field and now I want to subtract this integer from the current date with +year. (People type in their age and I want to calculate and save their approximate birthday).

Do you have any suggestions for me how to do this?

Thank you!

Nicola

3 Likes

The question you are asking is, â€śHow do I invert the sign on a numeric value?â€ť

The answer is: Multiply it by -1.

6 Likes

Iâ€™ve had this same problemâ€¦ and I didâ€™t think of your simple solution @keith, even though I consider myself a logically creative type

I think in Bubbleâ€™s desire to make itâ€™s product as intuitive as possible to non coders, adding -(days) etc would be a useful and not too difficult to implement solution!

1 Like

Hi Keith,

I already tried to do that, but it does not work. It seems that I cannot get the syntax right. Could you please show me exactly what I need to write.

Thank you!

Nicola

2 Likes

Yes, @nicola.kegel, I just tried this, and Bubble isnâ€™t giving me the option to do any multiplication on the value that follows +(days):

So I want to assign the date an eventâ€™s invoice is due with the syntax:

`Start Date +(days): Pay Within * -1`

So if Pay Within is 14, and Start Date is 14th April, the resulting payment due date is 1st April.

But Bubble doesnâ€™t give me the option to do multiplication following the assignment of Pay Within.

What to do? @keith, do you know how to do this?

Best wishes,

Antony.

2 Likes

Well, the expression entry field strikes again. (We kinda sorta do need â€ś-(days)â€ť to do this in one fell swoop.) Once your expression resolves to a date object, the expression is done.

So you *have to* do the negation first somewhere else.

In @nicola.kegel case, they have an input. That input will have a positive value in it (they ask the user â€śhow old are you?â€ť presumably meaning enter the number of years in age that you think you are).

So, they shouldnâ€™t be using the value from that input. They should put a custom state on that input. Call it â€śnegative yearsâ€ť or whatever (type number). Then they should have a â€śwhen that input is changedâ€ť workflow that simply does element > set state negative years to input years value * -1

And so their Make changes should look like:

Birthdate = Current date/time +(years): input How old are youâ€™s negative years

You would need to do something similar.

(This is a general issue with not having parens and such in the expression builder, @emmanuelâ€¦ The example above is sort of dumb, but this problem arises in more real situations where you really really really wish you just had -(interval). I have some complex date workflows where this crops up all the time and its truly a pain to go and figure out where we can do that negation precompute. Additionally, if this were an API workflow you would be well and truly effed as there is no place to do such a precompuation (though there will be if SSA performance can be improved â€“ on of the lil SSA plug-ins Iâ€™ve built is called a â€śflow stateâ€ť and its exactly what youâ€™d imagine â€“ an action that just holds a value (as a custom state does) for referencing in downstream workflow actions.)

5 Likes

Addendum: This is another argument in favor of a :negate operator that could/should be present on the boolean and number data types in Bubble. boolean:negate would return not(boolean). number:negate would return number with the opposite sign. This might be a more â€śBubblyâ€ť way to do things than duplicating all of the +(interval) operators with -(interval) operatorsâ€¦ but either would be most welcome.

Heck, if lazy, just give us :negate on all data types where the operator is a null function for data types for which it does not make sense (those types being Things, texts, dates, date ranges and date intervals).

EDIT: Strike thatâ€¦ this wonâ€™t actually help in this case as one would never be able to execute :negate. What we need is parens.

Thank you, this works.

Thank you for bringing this up again, Antony. I actually will report this as a bug. There should either be a -(days) or -(year) field or the option to multiply by -1 in the expression. Keithâ€™s solution is a workaround (thanks for that), but in my opinion thatâ€™s not how things should work.

9 Likes

Is this still a thing @emmanuel ? Iâ€™m trying to calculate a date - N days using data from a database item, but there is no way to subtract days and there seems to be no way to *-1 after +(days):

1 Like

Could you share an image of your expression?? It is working fine for meâ€¦

Agreed, this has got me stumped too. Yet again I find that very, very, very straightforward things that are trivial in every other system Iâ€™ve ever encountered, are incredibly, painfully difficult in bubble. So incredible, yet so flawed.

@keith your List Popper and Friends (SSA) Plugin has saved the day for me. I had to create

- FLOW State Single SSA to store the zero
- FLOW State Single SSA to subtract the number from zero => get the negative
- Calculate the date+(years): the result of 2.

What should literally have been as easy as either putting a - sign in front of a value from a Thing field, or choosing the non-existant :-(years) â€¦ has taken me **three hours** of frustration. @emmanuel and team please take note of the important request to implement subtraction from dates.

2 Likes

I am also struggling with this. :-days/years/hours, etc would save me pain.

So I have a similar issue.

I have a situation where something should not be visible until after a # of hours has expired. So I need to subtract the hour value they enter from a certain date to figure out when to show the item.

From this thread I see that there is no â€ś-hoursâ€ť option and (at least from what I see in this thread) there is no simple syntax to multiply the value by -1 within the calculation.

So I am taking the simple, to-hell-with-performance approachâ€¦and storing both the positive number they enter AND the negative number I need for the calculation.

Efficient? Nope.

Does it work? Yep.

Do we need -hours (and -months, -years, etc.)? Yep.