Skip to main content
Level 4
Aug 8, 2022 6:03 PM UTC
Solved

Dynamic date in email body

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
vinay16Accepted solution
Level 4
Aug 19, 2022 5:33 PM UTC

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

4 replies

ALangridge
Level 4
Aug 9, 2022 4:08 AM UTC

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-management/javascript-scripts-and-templates.html?lang=en 

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 

Translate
vinay16Author
Level 4
Aug 10, 2022 8:34 PM UTC

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 ?

Translate
Adobe Employee
Aug 18, 2022 2:48 PM UTC

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?

Translate
vinay16AuthorAccepted solution
Level 4
Aug 19, 2022 5:33 PM UTC

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

Translate