Day 5 – Offer different discounts based on dates

Challenge

https://ampscript30.com/ampscript-challenge-day5/

To offer different discounts depending on customers’ upcoming birthdays.

Solution

Hello %%=ProperCase(FirstName)=%%,

To celebrate your birthday, we are offering you a special discount!
%%[
SET @now = FormatDate(NOW(), 'MM/dd')
SET @birthdate = FormatDate(Birthdate, 'MM/dd')
SET @difference = DateDiff(@now, @birthdate, 'D')
IF @difference <= 7 AND @difference > 0 THEN
    SET @discount = '15%'
ELSEIF @difference > 7 AND @difference <= 14 THEN
    SET @discount = '10%'
ELSE
    SET @discount = '5%'
ENDIF
]%%

You will receive a %%=v(@discount)=%% discount on your next purchase.

Preview

Summary

There are different ways to achieve the goal depending on how the dates are manipulated.