1

I have a triggered email which is supposed to show a date which is 30 days from the date the email is received.

E.g. John Smith clicks something on a website and receives a triggered email today, June 25th and in his email he is encouraged to take an action by July 23rd (30 days from the moment he received the email). In this case, I need July 23rd, 2015 to appear dynamically in the email.

How can I add this sort of dynamic date into an email through AMPscript? Is there a function or something that calculates this and spits out the date?

2 Answers 2

2

Calculating the future date is fine, but it's not static. The AMPScript will get re-evaluated in certain scenarios -- like in the View As a Web Page page.

I would create a future date variable using the format() and dateadd() functions as suggested, but I would also retrieve it from the Triggered Send Data Extension or the SendLog, depending on the email context.

Something like this:

%%[
var @futureDate, @rs, @rows, @row, @futureDateFromDE

if _messageContext == "SEND" then
  set @futureDate = Format(DateAdd(Now(), "14", "D"), "MMMM dd")
else
  /* retrieve date value from appropriate data extension using a lookup function */
  set @futureDate = @futureDateFromDE
endif
]%%

Your trigger's target Data Extension or SendLog would need to have a futureDate column.

Reference: AMPScript Lookup Examples

6
  • thanks guys, so that means I have to have the date, the triggered email is sent, captured in a lookup DE?
    – Snowalker
    Commented Jun 26, 2015 at 12:44
  • You certainly don't have to, but I would. The capturing part is automatic as long as you have the futureDate column included in the DE defined in your Triggered Send Definition or the SendLog. Commented Jun 26, 2015 at 12:57
  • I have no idea how to capture the send date into a DE :( wouldn't be easier to just use the present time at the moment the user opens the email?
    – Snowalker
    Commented Jun 26, 2015 at 12:59
  • Sure. My point was that it's not static -- it'll change if they click through to the VAWP. If the VAWP isn't important, then just go with the format() and dateadd() Commented Jun 26, 2015 at 13:01
  • umm I will have to play a bit with format() / dateadd() and see if it does what I need. I'm wondering if the current date will be the one when I deploy the email or the one when the user opens - the user may open it multiple times and then we will end up with 30 days added every time they open...
    – Snowalker
    Commented Jun 26, 2015 at 13:31
4

Vic,

You can use the DateAdd() function for that.

Here is the function with formatting:

%%=Format(DateAdd(@today, "14", "D"), "MMMM dd")=%%

%%=DateAdd([insert date or variable here], "number to add", "Unit of time")=%%

Just a note this will be calculated based on the date sent, so if you send june 25 and the recipient does not open for 10 days, the date will still read July 23.

Hope this helps

Marsha

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .