CMS Development

mmcgrath1
Member

Email Template - Showing a Future Date (Always Next Thursday)

I'm looking to print a date in an email to always show the date of next Thursday. 

 

Using the below script I could print a date 21 days in advance but I'd like it to always calculate the date for next Thursday. 

 

{% set future_date = local_dt|plus_time(21, 'days')%}
{{ datetimeformat(future_date, '%B %e, %Y') }}

0 Upvotes
9 Replies 9
mmcgrath1
Member

Email Template - Showing a Future Date (Always Next Thursday)

Here it is in JS. 

function getNextThursday() {

var today = new Date();
var year = today.getFullYear();
var mes = today.getMonth()+1;
var dia = today.getDate() + ((7 - today.getDay() + 4) % 7 || 7);



var fecha = "Next Thursday - "+mes+"/"+dia+"/"+year;


return fecha;


}

 

 

0 Upvotes
GregSamsa
Contributor

Email Template - Showing a Future Date (Always Next Thursday)

I don't think you can use JS in email templates. Have you tried my Hubl solution? 

0 Upvotes
GregSamsa
Contributor

Email Template - Showing a Future Date (Always Next Thursday)

I don't know if I'm missing something, but couldn't you calculate it like this? 

{% set today = local_dt|datetimeformat("%w")%}
{% set thursday = 5 %}
{% if today >= thursday %}
  {% set diff = thursday - today + 7 %}
{% else %}
  {% set diff = thursday - today %}
{% endif %}
{% set date_on_thursday = local_dt|unixtimestamp + diff * 24 * 60 * 60 * 1000 %}

 {{ datetimeformat(date_on_thursday, '%B %e, %Y') }}
mmcgrath1
Member

Email Template - Showing a Future Date (Always Next Thursday)

How can i use this? Can I add this to the email somehow or is it using a workflow?  

 

 

0 Upvotes
GregSamsa
Contributor

Email Template - Showing a Future Date (Always Next Thursday)

You can add it to the email template or a custom module. Here's an example:

 

Screenshot 2022-09-13 at 09.11.42.png

Screenshot 2022-09-13 at 09.15.21.png

0 Upvotes
Bryantworks
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Email Template - Showing a Future Date (Always Next Thursday)

Hey @mmcgrath1,

 

You could get this to populate in an email, but you need to store this date on a record in HubSpot that's getting the email.  To calculate this, you would need a custom-coded action that runs on a weekly sync via HubSpot Ops Pro and then store that value in a property on the record under "Next Thursday Date" (or something similar).  Do you happen to hold a subscription there?

Chris Bryant | Your Dedicated HubSpot Expert
0 Upvotes
mmcgrath1
Member

Email Template - Showing a Future Date (Always Next Thursday)

Yes, we do. So create a property and create a workflow to produce the date. 

0 Upvotes
Bryantworks
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

Email Template - Showing a Future Date (Always Next Thursday)

Correct!  The custom coded action as well as setting up the workflow to run every Monday, etc. is the combination I'd use!

Chris Bryant | Your Dedicated HubSpot Expert
0 Upvotes
mmcgrath1
Member

Email Template - Showing a Future Date (Always Next Thursday)

Unable to write the script? Any example I could work off? 

0 Upvotes