CMS Development

vikram-mit
Participant

inserting date into email template

Résolue

i have email template for our lead follow up emails where we usually suggest a date 2 business days of sending the email. currently, it is a pain to manually update the date every time we send email. is there a way to insert it dynamically the way we can do the personalization attributes?

1 Solution acceptée
alyssamwilie
Solution
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

@LoraBergeron 

You can use the plus_time filter to get a future date from the current date, like so:

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

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.

Voir la solution dans l'envoi d'origine

33 Réponses
GMcDaniel7
Participant

inserting date into email template

Résolue

Hey what is the code for today's date?

 

I'm building a workflow that creates a daily task. To differentiate between days, I want it to be Task Title [Today's Date]. Therefore I just need the code for today's date. Can you please share?

0 Votes
alyssamwilie
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

Since this thread still gets activity just wanted to note that datetimeformat() has been deprecated and replaced with format_datetime, format_date, and format_time. I just released a blog post that talks about dynamic dates in detail with many exmaples of these new functions if you want to learn more : https://www.alyssawilie.com/blog/add-dynamic-dates-to-automated-emails

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
TPühringer
Contributeur

inserting date into email template

Résolue

Hello Alyssa,

i am not able to access your website.

is it permant offline?

Is the code working for one-to-one emails also?

Regards

 

LoraBergeron
Contributeur

inserting date into email template

Résolue

Thank you, thank you!!  Works perfectly!

0 Votes
alyssamwilie
Solution
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

@LoraBergeron 

You can use the plus_time filter to get a future date from the current date, like so:

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

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
alexpeck_akimbo
Participant

inserting date into email template

Résolue

Thank you! You helped us so much. 🙏🏼

0 Votes
Rob_Gordon
Participant

inserting date into email template

Résolue

Thanks for this. I've read the blog post also. 

I can't see where to add thi sinto an email template though? (https://app.hubspot.com/templates) If I paste it into the template it flags an error.

I want to be able to manually send an email to a client, select a template, and that template auto drop in todays date into it?

0 Votes
SMcInnes3
Membre

inserting date into email template

Résolue

Hi, I'm using this to insert a dynamic date into an email and it works great! I was wondering if it's possible to have the date appear inline with preceeding text? I'd like to have a line that reads, "Sale ends ________" but currently it will put the dynamically generated date onto the next line which looks odd.

Thanks,
Scott

0 Votes
alyssamwilie
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

You can put any extra text directly in the formatting string of the datetimeformat.

{{ datetimeformat(local_dt, 'Sale Ends %A, %B %e, %Y') }}



If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
0 Votes
SMcInnes3
Membre

inserting date into email template

Résolue
Thanks for the quick response. Would you mind showing me an example? I did try that but I must have done something wrong because it didn’t work. Thank you!
0 Votes
alyssamwilie
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

@SMcInnes3 
Screenshot in the editor:
datetimeformate-01.png


And how it shows in the actual email:

datetimeformat-02.png

 

If you're putting this in a section with columned content you'll want to make sure the column it's in is wide enough to accomodate the amount of text.

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
0 Votes
SMcInnes3
Membre

inserting date into email template

Résolue

Sorry, this is my first time trying something like this and I'm still doing something wrong. This is what I'm currently using but it splits it over 2 lines.

 

 Sale Ends {% set future_date = local_dt|plus_time(10, 'days')%}
{{ datetimeformat(future_date, '%B %e, %Y') }} at Midnight

 

Would like it all to appear on one line. Thanks again for being so helpful

0 Votes
alyssamwilie
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

Do this:

{% set future_date = local_dt|plus_time(10, 'days')%}
{{ datetimeformat(future_date, 'Sale Ends %B %e, %Y at Midnight') }}

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
0 Votes
SMcInnes3
Membre

inserting date into email template

Résolue
Amazing! Thank you very much!
0 Votes
YHandler
Membre

inserting date into email template

Résolue

hi there! 

 

how do we implement this ?

 

best,

jona

spogue
Contributeur de premier rang

inserting date into email template

Résolue

@alyssamwilie This is really great, thanks for the solution. I'm curious to how this would work if I only wanted to show the next 4 business days? If its showing today (a Thursday), it would show Friday, Monday, and Tuesday. Is that possible through Hubl?  

0 Votes
alyssamwilie
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue
@spogue Not sure if you can get them concurrently but you can use multiple plus_time calls to get the next three days and %A in the format to get the weekday.

{{ datetimeformat(local_dt|plus_time(1, 'days'), "%A") }}
{{ datetimeformat(local_dt|plus_time(2, 'days'), "%A") }}
{{ datetimeformat(local_dt|plus_time(3 , 'days'), "%A") }}

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
ShiranA
Contributeur | Partenaire solutions Diamond
Contributeur | Partenaire solutions Diamond

inserting date into email template

Résolue

Thank you! This was very helpful!

0 Votes
spogue
Contributeur de premier rang

inserting date into email template

Résolue

@alyssamwilie Makes sense. Have you ever seen code to only show business days?

 

For example, if I took the way you just wrote the code, but I only wanted to show the next 3 business days, is there a way to "skip" weekdays if one of those days is a Saturday or Sunday? Like this:

 

Friday, September 24, 2021

Monday, September 27, 2021

Tuesday, September 28, 2021

 

Thanks again for the help.

0 Votes
alyssamwilie
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

inserting date into email template

Résolue

@spogue  You can use a for loop and if statements to increase the plus_time if the weekday lands on a Saturday or Sunday. You'll probably want to put this in a custom module instead of directly in the email though.

 

{% for day in [1, 2, 3] %}
  {% if datetimeformat(local_dt|plus_time(day,'days'), '%A') == "Saturday" %}
    {{ datetimeformat(local_dt|plus_time(day + 2,'days'), '%A, %B %e, %Y') }}<br>
  {% elif datetimeformat(local_dt|plus_time(day,'days'), '%A') == "Sunday" %}
    {{ datetimeformat(local_dt|plus_time(day + 1,'days'), '%A, %B %e, %Y') }}<br>
  {% else %}
    {{ datetimeformat(local_dt|plus_time(day,'days'), '%A, %B %e, %Y') }}<br>
  {% endif %}
{% endfor %}

 

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.