I have 12 content blocks (for every month of the year) and would like to change the content on the 1st of every month. How do I accomplish this?
I have assumed that you create ContentBlocks for every month and name them with a pattern so you can code it very easily. For the code that is presented below you would need 12 different content blocks that are named:
Be aware of the fact that there is a limit of characters when you would use
%%[ /* Do variable declaration at the top for best practices */ var @today, @month, @contentBlockToGet /* Be aware of the difference between now() and now(1). Especially with VAWP */ /* Watch resources list below for Now() */ /* Now delivers the time in CET, which has to be transferred to the right timezone for the user, otherwise there might be problems, Watch resources list below for SystemDateToLocalDate() */ set @currentSystemTime = now(1) set @today = SystemDateToLocalDate(@currentSystemTime) set @month = DatePart(@today, "M") set @contentBlockToGet /* Just to test if Salesforce DatePart is correct :D */ IF @month >= 1 and @month <= 12 THEN set @contentBlockString = Concat("AWESOME_CONTENT_MONTH_",@month) ENDIF ]%% /* Somewhere Inside the Newsletter/Email */ /* To make it failsafe you can also create default content when your contentblock might not exist you would include additional parameters https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/contentblockbyname.htm https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/contentblockbykey.htm */ %%=ContentBlockByName(@contentBlockString)=%% /* OR */ %%=ContentBlockByKey(@contentBlockString)=%%
this below code use for getting 1st of every month try like this based on that you can display the content or post your code here what did try so far
%%[ set @today = now() set @monthOfThisMonth = DatePart(@today, "M") set @yearOfThisMonth = DatePart(@today, "Y") set @firstDayOfThisMonth = dateparse(concat(@monthOfThisMonth,"/01/",@yearOfThisMonth)) ]%% @today: %%=v(@today)=%% <br>@monthOfThisMonth: %%=v(@monthOfThisMonth)=%% <br>@yearOfThisMonth: %%=v(@yearOfThisMonth)=%% <br>@firstDayOfThisMonth: %%=v(@firstDayOfThisMonth)=%%