I'm trying to display dynamic date in email body. I was able to get dynamic date as per below --
<%
function daysInMonth(today) {
return new Date(today.getFullYear(), today.getMonth()+1, 0).getDate();
}
var today = new Date();
%>
<%= daysInMonth(today) %> <%= formatDate (today, "%Bl") %>
I want to display the day before the 2nd Thursday of every month. I'm not sure how to do that in ACM.
I was able to display this on webpage in a simple javascript.
Can anyone please help me ?
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
Yes, I meant to ask how to get 2nd Thursday of every month using JS inside a delivery. I have found the solution and tested it as well.
For anyone's reference, below can be used:
<% var ordinal = 2, weekday = 'Thu'; var today = new Date(); var d = new Date(today.getUTCFullYear(), today.getUTCMonth()+1, 1); d.setUTCHours(0, 0, 0, 0); var dayofWeek = 4; var ORDINALCONST = 7 * ordinal + dayofWeek - d.getUTCDay() - (d.getUTCDay() <= dayofWeek ? 7 : 0); d.setUTCDate(d.getUTCDate() + ORDINALCONST); %> <%= d.getDate() - 1 %> <%= formatDate (d, "%Bl %4Y") %>
I wanted to have a day before 2nd Thursday of next month and above code worked
Hey Vinay - I would probably try and get this working by using a javascript activity in the workflow to execute the script and store the output in a variable.
Info on variables - you probably want to look at an instance variable: https://experienceleague.adobe.com/docs/campaign-classic/using/automating-with-workflows/advanced-ma...
You can then pass this to be used in the email: https://blog.floriancourgey.com/2018/05/how-to-add-variables-from-a-workflow-in-a-delivery
Hi
Thank you for reply. This will be lengthy and tricky solution. Isn't there any solution like getting current date? and then we can make necessary changes to manipulate result ?
Views
Replies
Total Likes
Hi @vinay16,
The script you mentioned can be used inside a delivery. Is your question related to how to get the 2nd Thursday of every month or how to use the JS code in a delivery?
Views
Replies
Total Likes
Yes, I meant to ask how to get 2nd Thursday of every month using JS inside a delivery. I have found the solution and tested it as well.
For anyone's reference, below can be used:
<% var ordinal = 2, weekday = 'Thu'; var today = new Date(); var d = new Date(today.getUTCFullYear(), today.getUTCMonth()+1, 1); d.setUTCHours(0, 0, 0, 0); var dayofWeek = 4; var ORDINALCONST = 7 * ordinal + dayofWeek - d.getUTCDay() - (d.getUTCDay() <= dayofWeek ? 7 : 0); d.setUTCDate(d.getUTCDate() + ORDINALCONST); %> <%= d.getDate() - 1 %> <%= formatDate (d, "%Bl %4Y") %>
I wanted to have a day before 2nd Thursday of next month and above code worked