CMS Development

vikram-mit
Participante

inserting date into email template

resolver

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 Solução aceita
alyssamwilie
Solução
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

@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.

Exibir solução no post original

33 Respostas 33
GMcDaniel7
Participante

inserting date into email template

resolver

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 Avaliação positiva
alyssamwilie
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

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
Colaborador(a)

inserting date into email template

resolver

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
Colaborador(a)

inserting date into email template

resolver

Thank you, thank you!!  Works perfectly!

0 Avaliação positiva
alyssamwilie
Solução
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

@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
Participante

inserting date into email template

resolver

Thank you! You helped us so much. 🙏🏼

0 Avaliação positiva
Rob_Gordon
Participante

inserting date into email template

resolver

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 Avaliação positiva
SMcInnes3
Membro

inserting date into email template

resolver

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 Avaliação positiva
alyssamwilie
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

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 Avaliação positiva
SMcInnes3
Membro

inserting date into email template

resolver
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 Avaliação positiva
alyssamwilie
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

@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 Avaliação positiva
SMcInnes3
Membro

inserting date into email template

resolver

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 Avaliação positiva
alyssamwilie
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

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 Avaliação positiva
SMcInnes3
Membro

inserting date into email template

resolver
Amazing! Thank you very much!
0 Avaliação positiva
YHandler
Membro

inserting date into email template

resolver

hi there! 

 

how do we implement this ?

 

best,

jona

spogue
Top colaborador(a)

inserting date into email template

resolver

@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 Avaliação positiva
alyssamwilie
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver
@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
Colaborador(a) | Parceiro Diamante
Colaborador(a) | Parceiro Diamante

inserting date into email template

resolver

Thank you! This was very helpful!

0 Avaliação positiva
spogue
Top colaborador(a)

inserting date into email template

resolver

@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 Avaliação positiva
alyssamwilie
Especialista reconhecido(a) | Parceiro Elite
Especialista reconhecido(a) | Parceiro Elite

inserting date into email template

resolver

@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.