Tip of the Day: Working with Numbers and Dates in AMPScript

How to add rolling years to a chart image

SET @currTime = Now()
SET @label1 = FormatDate(DateAdd(@currTime, -2, "Y"),"YYYY")
SET @label2 = FormatDate(DateAdd(@currTime, -1, "Y"),"YYYY")
SET @label3 = FormatDate(@currTime,"YYYY")
SET @label4 = FormatDate(DateAdd(@currTime, 1, "Y"),"YYYY")

How to round 1.363636 to 1.4

Formatting the number as Decimal did not work because “The specified D format cannot be applied to double values (1.36363636363636). It is only valid for integer types.” Solution:

SET @time_to_sell_temp = divide(15, 11)
SET @time_to_sell = FormatNumber(@time_to_sell_temp,'N1')

On average, <model> cars are getting delisted 1.4x quicker than 60 days ago.

How to format a number into KMs

SET @kms = FormatNumber(AttributeValue("KMS"),"###,###,###,##")