Dynamic date in email body | Adobe Higher Education
Skip to main content
Level 4
August 8, 2022
Répondu

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.

Ce sujet a été fermé aux réponses.
Meilleure réponse par vinay16

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

2 commentaires

ALangridge
Level 4
August 9, 2022

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 

vinay16Auteur
Level 4
August 10, 2022

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 ?

Adobe Employee
August 18, 2022

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?

vinay16AuteurRéponse
Level 4
August 19, 2022

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