I have an integer field named "Priority" with values ranging from 5 to 30 days. I want to use the now() function to subtract the integer to give a new date. The formula I tried is below but it just returns a null value.

now() - to_interval("Priority")

It is slightly more complicated than the expression you have used in your question. If you are trying to populate a field with a date type, or a date & time type, then you need to use to_date function combined with now() to get the output of subtraction in date format.

Because your original field type of "Priority" is integer, you need to convert the values inside that field to string first before using to_interval. Also, to_interval takes string type like 5 days, 2 hours, or 5 days 2 hours (please read the help associated with the function), so you need to add in the expression || ' days' to concatenate the values in the "Priority" field with days.

Assuming the field type that you want to populate is a date type, as in the following example (the name Date field has a date type), here is the final expression:

to_date(now()) - to_interval(to_string("Priority") || ' days')

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.