1

I need to populate the last day of the month for the current month in the email.

Here is what I have so far. I am getting errors.

%%[ VAR @lastdaymonth

 SET @lastdaymonth = xtmonthnumeric]%%

 %%[ if %%= v(@lastdaymonth) =%% == "1" then ]%% 

January 31 

%%[ elseif %%= v(@lastdaymonth) =%% == "2" then ]%% 

February 28 

%%[ else %%= v(@lastdaymonth) =%% == "3" then ]%% 

March 31

etc.....

%%[ endif ]%% 
1
  • 1
    welcome to salesforce.stackexchange! Your question may be easier to answer if you also update it with the errors you are getting. Commented Feb 11, 2014 at 16:28

3 Answers 3

3

Here is some code that shows the last day of any current month:

%%[ <br/>
set @firstday=Format(concat(DatePart(Now(),"month"),"/01/",DatePart(Now(),"year")),"MM/dd/yy")<br/> set @nextmonth = DateAdd(@firstday,"1","M") <br/>
set @lastday = Format(DateAdd(@nextmonth,"-1","D"),"MM/dd/yy") <br/>
]%% <br/>
<br/>
%%=v(@firstday)=%% and ends %%=v(@lastday)=%%
0

AMPScript blocks cannot be nested, so if there is a need to reference a variable just use the variable name, it does not need to be wrapped in %%=v()=%%, please try:

%%[ VAR @lastdaymonth

 SET @lastdaymonth = xtmonthnumeric]%%

 %%[ if @lastdaymonth == "1" then ]%% 

January 31 

%%[ elseif @lastdaymonth == "2" then ]%% 

February 28 

%%[ else @lastdaymonth == "3" then ]%% 

March 31

etc.....

%%[ endif ]%% 
0

K-grifin, Your answer was very helpful as I needed to display a coupon code expiration date, expiring on the last day of the following month. All that was necessary was a slight change to the code you provided in order to achieve that goal.

Thanks, Steve

%%[
set @firstday=Format(concat(DatePart(Now(),"month"),"/01/",DatePart(Now(),"year")),"MM/dd/yy")
set @skipmonth = DateAdd(@firstday,"2","M")
set @expday = Format(DateAdd(@skipmonth,"-1","D"),"MM/dd/yy")
]%%

%%=v(@expday)=%%
0

You must log in to answer this question.

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