0

I'm trying to change the content depending on the day as you can see in the code below. When I set the format to "ddd" and write Mon, Tue, Wed etc. it doesn't work. However, when I change the format to "dddd" it works fine. I'm a bit concerned that it isn't working as described in the documentation. Am I missing something here?

%%[
SET @Day = FormatDate(NOW(), "ddd")


IF @Day == "Mon" THEN

    SET @SMSContent = "Hello!"
    SET @Link = "http://example.com"

ELSEIF @Day == "Tue" THEN

    SET @SMSContent = "Hello!"
    SET @Link = "http://example.com"

ELSEIF @Day == "Fri" THEN

    SET @SMSContent = "Hello!"
    SET @Link = "http://example.com" 

ENDIF

]%%


%%=v(@SMSContent)=%% %%=v(@Link)=%% 
3
  • SFMC documentation has all sorts of problems. I'd test it. – Adam Spriggs Oct 14 '17 at 14:48
  • Also, you're writing out the same thing for each day. Is that intended? – Adam Spriggs Oct 14 '17 at 14:48
  • That was only for the purpose of showing an example it's not my actual content. – cmccarra Oct 20 '17 at 9:46
0

I'd suggest writing it out the day to verify the documentation (it's not always right). Might be easier to test in the body of an email.

%%[

SET @Day = FormatDate(NOW(), "dddd")

output(concat("dddd: ", @Day))

SET @Day = FormatDate(NOW(), "ddd")

output(concat("ddd: ", @Day))

IF @Day == "Mon" THEN

    output(concat("(Mon) Hello! http://example.com"))

ELSEIF @Day == "Tue" THEN

    output(concat("(Tue) Hello! http://example.com"))


ELSEIF @Day == "Fri" THEN

    output(concat("(Fri) Hello! http://example.com"))

ENDIF

]%%
3
  • Thanks Adam, so it's basically just that the Salesforce documentation is wrong. The only format that seems to work is setting FormatDate = "dddd" and using "Mon", "Fri", "Tue" etc. Everything else seems to fail for me. – cmccarra Oct 20 '17 at 9:58
  • Please utilize the feedback icon on the right side of the page -- the [ + ] thing -- and report the problem with the documentation. I'm sure they're tired of hearing from me. – Adam Spriggs Oct 20 '17 at 13:26
  • Yeah already did! – cmccarra Oct 20 '17 at 18:18
-1

If your users are in time zones that cross the International Date Line (IDL)... Ie. One in US and one in Japan, you can find the first day of that days week and then add days to it and then test your expected date against the result.

To do this you would use:

Date myDate = Date.today();
Date weekStart = myDate.toStartofWeek();  //The result of this will return the week start
//day based on the Local, hence bad for users that may be across the IDL. 
Date d = weekStart.date().addDay(1);

If they are not going to be crossing the IDL, you can do it a bit easier.

// Cast the Date variable into a DateTime
DateTime myDateTime = (DateTime) myDate;
String dayOfWeek = myDateTime.format('E');
// dayOfWeek is Sun, Mon, Tue, etc.
1
  • 1
    The OP's asking about AMPScript in Marketing Cloud. – Adam Spriggs Oct 14 '17 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.