CMS Development

vikram-mit
Teilnehmer/-in

inserting date into email template

lösung

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 Akzeptierte Lösung
alyssamwilie
Lösung
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

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

Lösung in ursprünglichem Beitrag anzeigen

33 Antworten
GMcDaniel7
Teilnehmer/-in

inserting date into email template

lösung

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 Upvotes
alyssamwilie
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

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
Mitwirkender/Mitwirkende

inserting date into email template

lösung

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
Mitwirkender/Mitwirkende

inserting date into email template

lösung

Thank you, thank you!!  Works perfectly!

0 Upvotes
alyssamwilie
Lösung
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

@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
Teilnehmer/-in

inserting date into email template

lösung

Thank you! You helped us so much. 🙏🏼

0 Upvotes
Rob_Gordon
Teilnehmer/-in

inserting date into email template

lösung

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 Upvotes
SMcInnes3
Mitglied

inserting date into email template

lösung

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 Upvotes
alyssamwilie
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

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 Upvotes
SMcInnes3
Mitglied

inserting date into email template

lösung
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 Upvotes
alyssamwilie
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

@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 Upvotes
SMcInnes3
Mitglied

inserting date into email template

lösung

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 Upvotes
alyssamwilie
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

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 Upvotes
SMcInnes3
Mitglied

inserting date into email template

lösung
Amazing! Thank you very much!
0 Upvotes
YHandler
Mitglied

inserting date into email template

lösung

hi there! 

 

how do we implement this ?

 

best,

jona

spogue
Stratege/Strategin

inserting date into email template

lösung

@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 Upvotes
alyssamwilie
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung
@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
Mitwirkender/Mitwirkende | Diamond Partner
Mitwirkender/Mitwirkende | Diamond Partner

inserting date into email template

lösung

Thank you! This was very helpful!

0 Upvotes
spogue
Stratege/Strategin

inserting date into email template

lösung

@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 Upvotes
alyssamwilie
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

inserting date into email template

lösung

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