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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Converting English Months to French in ACC

cslackl1
Level 2
Level 2

hey!

First run at ACC here, and trying to convert the current date into French months:

 

<%= formatDate(new Date(), "%D %Bi %Y") %>,

 

So instead of 20 July 2020, i would it to say 20 juillet 2020

6 Replies
Manoj_Kumar_
Community Advisor
Community Advisor

Hello @cslackl1 ,

 

You can use moment.js in your workflow to achieve this.

 

Just download the moment.js library (from here). Then upload it in Administration > Configuration > JavaScript Codes

 

Then in your workflow you can use this code.

loadLibrary('NAMESPACE:moment.js');
var myDate=formatDate(new Date(), "%D %Bi %Y");
var frenchDate=moment(myDate, 'DDD MMMM YYYY', 'fr');

More Information on date formatting is available here: https://momentjs.com/docs/#:~:text=moment(%2212%2D25%2D,valid%20dates%20over%20invalid%20ones.

Let me know if that works.

cslackl1
Level 2
Level 2
Thank you! As i dont have access to admin panel yet, I cannot try this but i have asked my admin to load it.
cslackl1
Level 2
Level 2
Hey Manoj, so i got the lib installed, and im not getting an error, but im not sure how to display the date now?, I have added that script inside the email.
cslackl1
Level 2
Level 2

Hey Jonathon, Thanks!
Hey! My problem is the correct syntax, as i am new to eJS (coming from Freemarker) i cant seem to get it right:

 

<%= formatDate(toLocaleDateString('fr-CA), "%D %Bl, %Y") %>

 

Doesnt seem to work, but chances are im not coding it correctly.

cslackl1
Level 2
Level 2
Hey! My problem is the correct syntax, as i am new to eJS (coming from Freemarker) i cant seem to get it right:
Jonathon_wodnicki
Community Advisor
Community Advisor

Use the below, remove any js libs installed for this:

<%=
new Date().toLocaleDateString('fr-CA', {
  year: 'numeric',
  month: 'long',
  day: 'numeric'
});
%>

Thanks,

-Jon 

cslackl1
Level 2
Level 2

Hey Jon,

 

I added that script to my personalization block, and called that into my delivery, and i am getting this error:

Error while evaluating document

JST-310000 Error while compiling script 'content htmlContent' line 20: missing ) after argument list (line=' }); ' token='; ').
SCR-160032 Javascript&colon; error while compiling script 'content htmlContent'.
JST-310007 Unable to compile script (content htmlContent).