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

Insert month, based on dat field, into E-Mail

roberts32477966
Level 2
Level 2

Hi all,

i would like to inster something like "September 2018" into an E-Mail. This should/could a personalization block or directly as personalization into the email. The month and year should based on a date field with the following format: 2017/08/31 00:00:00.

I guess putting an javascript for the calculation and the return, but I could not create the correct syntax.

Many thanks and br

Robert

1 Accepted Solution
Pabst_dk
Correct answer by
Level 3
Level 3

Hi Robert,

You can use the following script to insert the date in the format you are looking for

<%

var monthNames = ["January", "February", "March", "April", "May", "June",  "July", "August", "September", "October", November", "December"];

var d = new Date();

document.write(monthNames[d.getMonth()] + " " + (d.getFullYear()));

%>

Hope this solves the issue you are facing,

Else please specify more narrow

Best Regards,

Jonas

View solution in original post

4 Replies
Pabst_dk
Correct answer by
Level 3
Level 3

Hi Robert,

You can use the following script to insert the date in the format you are looking for

<%

var monthNames = ["January", "February", "March", "April", "May", "June",  "July", "August", "September", "October", November", "December"];

var d = new Date();

document.write(monthNames[d.getMonth()] + " " + (d.getFullYear()));

%>

Hope this solves the issue you are facing,

Else please specify more narrow

Best Regards,

Jonas

View solution in original post

roberts32477966
Level 2
Level 2

Wow great...fter I set an additional " n fornt of november it works many thanks for that fast help!

Jean-Serge_Biro
Community Advisor
Community Advisor

Hi Roberts,

Alternative way to mention, please see the standard Adobe Campaign JSAPI function formatDate().
It is recommended over standard Javascript function, it eases date manipulation, especially timezone management, locale language and default format or specific format.

Examples:

ctx.vars.datetime_day = formatDate(getCurrentDate(),"%4Y-%2M-%2D %02H:%02N:%02S")

in your case, the format to use is:

"%Bl %4Y"

So in case of English language, it generates "September 2018", but in case of French, it generates "septembre 2018" (without Smart Capitalization) automatically.

Regards.

J-Serge

roberts32477966
Level 2
Level 2

Hi Jean, okay that sounds plausible. I will test it as well.