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

roberts32477966

01-09-2017

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

Accepted Solutions (1)

Accepted Solutions (1)

Pabst_dk

01-09-2017

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

Answers (3)

Answers (3)

Jean-Serge_Biro

MVP

01-09-2017

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