Printing the last weekday in content editor for email

Avatar

Avatar

oscarr88498187

Avatar

oscarr88498187

oscarr88498187

27-11-2018

Hi I have a question regarding date formatting in content editor. I want to be able to set up so that the last friday of a month is being displayed in the following way:

"Do not forget to get back to us by Friday DD Month"

Where Friday DD Month equal the date of the last friday e.g. Friday 29 November.

How can I achieve this?

KR

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

wodnicki

MVP

Avatar

wodnicki

MVP

wodnicki
MVP

04-01-2019

Hi,

Use this:

Do not forget to get back to us by <%

var dt = new Date(); // fill with desired date, e.g. new Date(@date), or leave empty for time of send

var eom = new Date(dt.getFullYear(), dt.getMonth() + 1, 0);

var lf = new Date(eom.getFullYear(), eom.getMonth(), eom.getDate() - (7 - Math.abs(eom.getDay() - 5)) % 7);

document.write(lf.toLocaleDateString('en-Us', {weekday: 'long', day: 'numeric', month: 'long'}));

%>

Thanks,

-Jon

Answers (0)