Subtract Function

The Subtract function can be used to return the difference of two numbers.

Use case: the Subtract function can be used for a quick way to get the difference of two numerical values including negative numbers as well. For example, if you need to subtract the current year to the birth year of a subscriber to get the age. Note that this function is limited to just two numbers in the equation but more numbers can be nested together by adding another Subtract function.

Syntax:



Subtract(1,2)
1 = Number of the first value in to subtract from (number or decimal datatype)
2 = Number of the second value in subtraction equation (number or decimal datatype)

Example:



%%[
set @numbervar1 = ‘2022’
set @numbervar2 = ‘1953’
]%%
%%=Subtract(@numbervar1,@numbervar2)=%%




Output:

69

Explanation:

In the Subtract example above, the two variables are hardcoded with the numbers ‘2022’ for the current year and ‘1953’ for the year of birth. Subtracting both of those numbers together gets you the number of 69 (nice!)

The Subtract function can be used for whole numbers or decimals. The datatype for these values should be a number datatype or decimal or you can hardcode the numbers as it is shown in the example above.

Related functions are the Divide, Multiply, and Add functions.

Leave a Reply

Your email address will not be published. Required fields are marked *