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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Printing the last weekday in content editor for email

oscarr88498187
Level 1
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
wodnicki
Correct answer by
Community Advisor
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
wodnicki
Correct answer by
Community Advisor
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