Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

The 4th edition of the Campaign Community Lens newsletter is out now!
SOLVED

Date format with sup \'st\', \'rd\', \'nd\', \'th\' in email delivery

Avatar

Level 3

Hi,

I have created a email delivery where i need to insert date in the format August 21st,2019  (or)  August 21st, 2019.

I have used this script        <%= formatDate(new Date(), "%Bl %D,%4Y") %>

From this, I am able to get August 21,2019. but i want 'st',' nd,' rd', 'th' after the date. How can i get that?

Please help me with this!

Regards,

Partha.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

Use this:

<%= formatDate(new Date(), '%Bl %D, %4Y').replace(/\d+/, function ($1) {return $1 + (

  $1 == 31 || $1 == 21 || $1 == 1 ? 'st' :

  $1 == 22 || $1 == 2 ? 'nd' :

  $1 == 23 || $1 == 3 ? 'rd' :

  'th'

)}) %>

Thanks,

-Jon

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi,

Use this:

<%= formatDate(new Date(), '%Bl %D, %4Y').replace(/\d+/, function ($1) {return $1 + (

  $1 == 31 || $1 == 21 || $1 == 1 ? 'st' :

  $1 == 22 || $1 == 2 ? 'nd' :

  $1 == 23 || $1 == 3 ? 'rd' :

  'th'

)}) %>

Thanks,

-Jon

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now