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’) }}
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?
Yes, we do. So create a property and create a workflow to produce the date.
Correct! The custom coded action as well as setting up the workflow to run every Monday, etc. is the combination I’d use!
Unable to write the script? Any example I could work off?
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') }}
How can i use this? Can I add this to the email somehow or is it using a workflow?
You can add it to the email template or a custom module. Here’s an example:
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;
}
I don’t think you can use JS in email templates. Have you tried my Hubl solution?