Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Printing the last weekday in content editor for email

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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