I have an automated email that will be sent every month and I'm trying to get the expiry to reference the last date of the current month formatted to read 31st January, 2019 or 28th February, 2019. I'm currently using:

%%[ <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"),"d MMMM, yyyy") <br/>
]%% <br/>

Date: %%=v(@lastday)=%%


31 August, 2019

Is there a way I can get st or th to sit after the numeric value?


Not exactly ideal solution, but could do datepart() to get day month year and then do a conditional to append the correct 'st' or 'th'.

For instance:

Set @day = datepart(@endmonthdate, 'D')
Set @month = datepart(@endmonthdate, 'M')
Set @year = datepart(@endmonthdate, 'Y')

If length(@day) > 1 then

  Set @dayend = substring(@day, 2, 1)


  Set @dayend = @day


If @day == 11 OR @day == 12 OR @day == 13 then

  Set @ append = "th"

ElseIf @dayend == 1 then

  Set @append = "st"

Elseif @dayend == 2 then

  Set @append = "nd"

Elseif @dayend == 3 then

  Set @append = "rd"


  Set @append = "th"


Set @dayoutput = Concat(@day,@append, ' ',@month,' ',@year))

This may not be 100% accurate. I am typing this on my phone in my bed in disney, so may be best to treat it more as pseudo code.

| improve this answer | |

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.