Printing the last weekday in content editor for email | Community
Skip to main content
oscarr88498187
November 27, 2018
Solved

Printing the last weekday in content editor for email

  • November 27, 2018
  • 1 reply
  • 1426 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jonathon_wodnicki

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

1 reply

Jonathon_wodnicki
Community Advisor
Jonathon_wodnickiCommunity AdvisorAccepted solution
Community Advisor
January 4, 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