I'm on a learning curve with AMPscript and need to add a time frame to a Exclusion Script.

Basically I'm using the exclusion script below in a Trigger Send. But I would like to add a time frame.

Rowcount(LookupRows("Data Extension Name", "EmailAddress", emailaddr))>1

So I want the code exclude Contacts in the DE that received email from this Trigger Send in the last 2 hours.

Is it possible?

1 Answer 1


Unfortunately, all of the AMPScript lookup functions use only AND conditions with = operators, which means, you can't use criteria like insertDate > DateAdd(now(1), -2, "H")

Theoretically, if your triggered send data extension included a column that you could match exactly (with an = operator) then you could do it.

To do that you'd need to add an insertDateStr column to your TSD DE and then include this code in your email AMPscript.


var @insertDateStr
set @intertDateStr = formatDate(now(1),"YYYYMMddhh"))


Then your exclusion script could be something like this:

Rowcount(LookupRows("Data Extension Name", "EmailAddress", emailaddr, "insertDateStr", formatDate(now(1),"YYYYMMddhh"))) > 1 
OR Rowcount(LookupRows("Data Extension Name", "EmailAddress", emailaddr, "insertDateStr", formatDate(DateAdd(now(1), -1, "H"),"YYYYMMddhh"))) > 0

First one catches anyone in the current hour. Rows are written to the DE first and then the email is sent, which is why it needs to be > 1.

The second one catches any rows for the previous hour.

To test this before updating your Triggered Send Definition, you could add the exclusion script code to the email code and output the results, then review it against rows that qualify (or not).

Let us know how it goes! This is an interesting scenario.


To test in the email code you can do something like this:


var @insertDateStr
set @intertDateStr = formatDate(now(1),"YYYYMMddhh"))

var @rc1, @rc2

set @rc1 = Rowcount(LookupRows("Data Extension Name", "EmailAddress", emailaddr, "insertDateStr", formatDate(now(1),"YYYYMMddhh"))) 

set @rc2 = Rowcount(LookupRows("Data Extension Name", "EmailAddress", emailaddr, "insertDateStr", formatDate(DateAdd(now(1), -1, "H"),"YYYYMMddhh"))) 

output(concat("<br>insertDateStr: ", @insertDateStr)
output(concat("<br>rc1: ", @rc1)
output(concat("<br>rc2: ", @rc2)


NOTE: Be sure that the LookupRow functions are retrieving from the data extensions configured in your triggered send definition.

  • I believe we've missed a round bracket on the Exclusion Script before "> 0". I did everything as sugested but no data is flowing to the "insertDateStr" collum. And it seems the Exclusion Script is excluding everyone. Because now this Trigger sends are getting queued. I'm trying ro make it work. : )
    – Alan
    May 6, 2019 at 21:20
  • Updated. I'd definitely test this code in the email code instead of in the TSD as an exclusion. May 6, 2019 at 22:37
  • I tried to put the code in email like this: imgur.com/57XAPL2 But it's not working... Am I doing something wrong?
    – Alan
    May 9, 2019 at 12:32
  • updated my answer above May 9, 2019 at 17:49

You must log in to answer this question.

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