0

Trying to expand on this original post to generate dynamic content based on a specific season of the year.

Loading content block using AMPScript based on specific date of the year

I updated my code as follows, but my is statement only seems to be showing the first block of dynamic content (Fall) and not following the conditional rules (which should be showing Spring based on the dates).

%%[
var @dateStartSpring,
  @dateEndSpring,
  @dateStartSummer,
  @dateEndSummer,
  @dateStartFall,
  @dateEndFall,
  @dateStartWinter,
  @dateEndWinter,
  @dateNow,
  @nextYear,
  @thisYear

/* all times in UTC; see documentation */
set @dateNow = DateParse(Format(Now(), 'yyyy/MM/dd hh:mmtt'), 1)
set @thisYear = DatePart(@dateNow, 'Y')
set @nextYear = Add(@thisYear, 1)
set @dateStartSpring = DateParse(Concat(@thisYear, '/10/01 00:00AM'), 1)
set @dateEndSpring = DateParse(Concat(@nextYear, '/12/22 11:59PM'), 1)
set @dateStartSummer = DateParse(Concat(@thisYear, '/02/01 00:00AM'), 1)
set @dateEndSummer = DateParse(Concat(@nextYear, '/02/22 11:59PM'), 1)
set @dateStartFall = DateParse(Concat(@thisYear, '/03/01 00:00AM'), 1)
set @dateEndFall = DateParse(Concat(@nextYear, '/03/22 11:59PM'), 1)
set @dateStartWinter = DateParse(Concat(@thisYear, '/01/01 00:00AM'), 1)
set @dateEndWinter = DateParse(Concat(@nextYear, '/01/22 11:59PM'), 1)

if (@dateNow >= @dateStartFall) and (@dateNow <= @dateEndFall) then
]%%
%%=ContentBlockbyId(96850)=%%
%%[elseif (@dateNow >= @dateStartWinter) and (@dateNow <= @dateEndWinter) then
]%%
%%=ContentBlockbyId(96859)=%%
%%[elseif (@dateNow >= @dateStartSummer) and (@dateNow <= @dateEndSummer) then
]%%
%%=ContentBlockbyId(96845)=%%
%%[elseif (@dateNow >= @dateStartSpring) and (@dateNow <= @dateEndSpring) then
]%%
%%=ContentBlockbyId(96854)=%%
%%[else
]%%
%%=ContentBlockbyId(96865)=%%
%%[
endif
]%%
2
  • 3
    Hi @kcalero, how can you test this? because content related to Spring will load only when you send it at the spring time. Can you please help me to understand a bit more on how you have tested?
    – Naveen VM
    Nov 9, 2019 at 7:49
  • yes @razor, I tried rotating the dates to get different versions to show up and make sure it is working as expected. Trying to work through it more this morning, so any advice is greatly appreciated.
    – kcalero
    Nov 11, 2019 at 14:28

2 Answers 2

0

I have found the issues like this before and I used to do some programming logic to personalization the content by using this function in the Ampscript: DateDiff() I hope this could help Ref: https://ampscript.guide/datediff/

0

Thank you both for your suggestions, but I found a simpler way to fix my code. I was able to make this work using both 'Preview and Send' and actual Sends. I also included a default version in the 'Else' near the end in case something goes wrong and no conditionals are met.

%%[
  Var @month, @day
  Set @month = DatePart(NOW(), 'month')
  Set @day = DatePart(NOW(), 'day')

IF (@month >= 3) and (@month < 6) then
]%%
%%=ContentBlockbyId(96845)=%%
%%[ELSEIF (@month >= 6) and (@month < 9) then
]%%
%%=ContentBlockbyId(96850)=%%
%%[ELSEIF (@month >= 9) and (@month < 12) then
]%%
%%=ContentBlockbyId(96854)=%%
%%[ELSEIF (@month >= 12) or (@month < 3) then
]%%
%%=ContentBlockbyId(96859)=%%
%%[ELSE
]%%
%%=ContentBlockbyId(96865)=%%
%%[
ENDIF
]%%

You must log in to answer this question.

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