0

I have the following block of AmpScript at the top of an email in Marketing Cloud

%%[
var @now, @cdp, @bookingStart, @bookingEnd, @pickupStart, @pickupEnd

SET @now = now()

/* MAY17 */
IF (now() > "5/18/2017 00:00 AM" AND now() < "6/08/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "18/05/2017"
SET @bookingEnd = "08/16/2017"
SET @pickupStart = "19/05/2017"
SET @pickupEnd = "14/06/2017"

/* JUN17 */
ELSEIF (now() > "6/15/2017 00:00 AM" AND now() < "6/30/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "15/06/2017"
SET @bookingEnd = "30/06/2017"
SET @pickupStart = "16/06/2017"
SET @pickupEnd = "30/06/2017"
SET @now = "JUNE"

/* JUL17 */
ELSEIF (now() > "7/20/2017 00:00 AM" AND now() < "8/10/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "20/07/2017"
SET @bookingEnd = "10/08/2017"
SET @pickupStart = "18/08/2017"
SET @pickupEnd = "08/09/2017"

/* AUG17 */
ELSEIF (now() >= "8/17/2017 00:00 AM" AND now() <= "9/07/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "17/08/2017"
SET @bookingEnd = "07/09/2017"
SET @pickupStart = "09/09/2017"
SET @pickupEnd = "30/09/2017"

/* SEP17 */
ELSEIF (now() > "9/21/2017 00:00 AM" AND now() < "10/12/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "21/09/2017"
SET @bookingEnd = "12/10/2017"
SET @pickupStart = "22/09/2017"
SET @pickupEnd = "18/10/2017"

/* OCT17 */
ELSEIF (now() > "10/19/2017 00:00 AM" AND now() < "11/09/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "19/10/2017"
SET @bookingEnd = "09/11/2017"
SET @pickupStart = "20/10/2017"
SET @pickupEnd = "15/11/2017"

/* NOV17 */
ELSEIF (now() > "11/16/2017 00:00 AM" AND now() < "12/07/2017 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "16/11/2017"
SET @bookingEnd = "07/12/2017"
SET @pickupStart = "17/11/2017"
SET @pickupEnd = "14/12/2017"

/* DEC17 */
ELSEIF (now() > "12/21/2017 00:00 AM" AND now() < "1/11/2018 23:59 PM") THEN
SET @cdp = "***"
SET @bookingStart = "21/12/2017"
SET @bookingEnd = "11/01/2018"
SET @pickupStart = "27/12/2017"
SET @pickupEnd = "28/01/2018"
ENDIF
]%%

In the body of the email I am outputting all the variables in the IF block, but get an empty string back for each one.

... by %%=v(@bookingEnd)=%% using CDP %%=v(@cdp)=%%. ...

The output of %%=v(@now)=%% is

6/14/2017 7:48:08 AM

Note: Actual CDP codes have been replaced with "***" in the above code.

4
  • Does @bookingEnd output anything, or is it blank as well? Commented Jun 14, 2017 at 13:52
  • Hi @Gortonington sorry should have clarified that. Yes all variables in the IF block are blank.
    – terrorfall
    Commented Jun 14, 2017 at 13:53
  • Some of the dates aren't covered, for example in your first IF it goes from 5/18 to 6/08, but the next if statement only covers from 6/15 to 6/30. Anything from 6/08 to 6/15 will get no info inserted as there is no ELSE condition. Is this on purpose? Commented Jun 14, 2017 at 14:48
  • 1
    Hi @Gortonington yeah... this is not on purpose! Just saw that myself and came back to update the question. Reason I'm not getting a variable back is because today's date is not covered in the IF statement... man, what an idiot! Feel free to add this as the answer and I'll accept
    – terrorfall
    Commented Jun 14, 2017 at 14:54

1 Answer 1

2

Some of your dates are not covered inside your IF statement.

For example in your first IF statement it goes from 5/18 to 6/08, but the next IF statement only covers from 6/15 to 6/30. Anything from 6/08 to 6/15 will get no info inserted as there is no ELSE condition.

I would recommend either covering each date, or adding a 'catch all' ELSE statement to handle those that do not fit inside the specified dates.

Also, for brevity and efficiency's sake, I would change the way you are handling the date as a variable by using FORMATDATE().

See below as an example:

%%[
var @now, @cdp, @bookingStart, @bookingEnd, @pickupStart, @pickupEnd

SET @now = FORMATDATE(Now(), "YYYYMMDD")

/* MAY17 */
IF (@now > 20170518 AND @now < 20170608) THEN
SET @cdp = "***"
SET @bookingStart = "18/05/2017"
SET @bookingEnd = "08/16/2017"
SET @pickupStart = "19/05/2017"
SET @pickupEnd = "14/06/2017"

/* JUN17 */
ELSEIF (@now > 20170615 AND @now < 20170630) THEN
SET @cdp = "***"
SET @bookingStart = "15/06/2017"
SET @bookingEnd = "30/06/2017"
SET @pickupStart = "16/06/2017"
SET @pickupEnd = "30/06/2017"
SET @now = "JUNE"

/* JUL17 */
ELSEIF (@now > 20170720 AND @now < 20170810) THEN
SET @cdp = "***"
SET @bookingStart = "20/07/2017"
SET @bookingEnd = "10/08/2017"
SET @pickupStart = "18/08/2017"
SET @pickupEnd = "08/09/2017"

/* AUG17 */
ELSEIF (@now >= 20170817 AND @now <= 20170907) THEN
SET @cdp = "***"
SET @bookingStart = "17/08/2017"
SET @bookingEnd = "07/09/2017"
SET @pickupStart = "09/09/2017"
SET @pickupEnd = "30/09/2017"

/* SEP17 */
ELSEIF (@now > 20170921 AND @now < 20171012) THEN
SET @cdp = "***"
SET @bookingStart = "21/09/2017"
SET @bookingEnd = "12/10/2017"
SET @pickupStart = "22/09/2017"
SET @pickupEnd = "18/10/2017"

/* OCT17 */
ELSEIF (@now > 20171019 AND @now < 20171109) THEN
SET @cdp = "***"
SET @bookingStart = "19/10/2017"
SET @bookingEnd = "09/11/2017"
SET @pickupStart = "20/10/2017"
SET @pickupEnd = "15/11/2017"

/* NOV17 */
ELSEIF (@now > 20171116 AND @now < 20171207) THEN
SET @cdp = "***"
SET @bookingStart = "16/11/2017"
SET @bookingEnd = "07/12/2017"
SET @pickupStart = "17/11/2017"
SET @pickupEnd = "14/12/2017"

/* DEC17 */
ELSEIF (@now > 20171221 AND @now < 20180111) THEN
SET @cdp = "***"
SET @bookingStart = "21/12/2017"
SET @bookingEnd = "11/01/2018"
SET @pickupStart = "27/12/2017"
SET @pickupEnd = "28/01/2018"

ELSE

 /* Your catch all info */

ENDIF
]%%

You must log in to answer this question.

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