CMS Development

ben-duchy
Top Contributor

Display date for each day of the week

SOLVE

Hello, Does anyone know if it's possible to automatically display todays date (and beyond) without adding a date column within HubDB?

I've created a very simple table within HubDB consisting of 2 columns - 'days of the week' and 'opening times'. I now want to add in the relevant date underneath each day without having to manually update hubdb each day. Is this possible?

1 Accepted solution
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Display date for each day of the week

SOLVE

@ben-duchy there is a "plus_time" filter made specifically for this: https://developers.hubspot.com/docs/cms/hubl/filters#plus-time

 

It can be used in combination with the datetimeformat filter like so:

{{ content.updated|plus_time(1, 'days')|datetimeformat('%B %e, %Y') }}

 

Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

9 Replies 9
sharonlicari
Community Manager
Community Manager

Display date for each day of the week

SOLVE

Thank you for sharing this @ben-duchy 

 

I'll tag a few experts that can share their thoughts with you 

 

Hey @John @piersg @stefen any advise for @ben-duchy?

 

Thank you 🙂

Sharon 


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




ben-duchy
Top Contributor

Display date for each day of the week

SOLVE

I've found the solution to display todays date:

{{ content.updated|datetimeformat('%B %e, %Y') }}

 

But how do I add a 'plus 1' for tomorrows date and 'plus 2' for the day after etc?

piersg
Key Advisor

Display date for each day of the week

SOLVE

Hi @ben-duchy (thanks @sharonlicari)

 

You can do this:

 

 

//get today's date in unix timestamp in seconds
{% set today = (local_dt|unixtimestamp)//1000 %}

//one day in unix timestamp is 86400s long
{% set day = 86400 %}

//get tomorrow's/yesterday's date by adding or subtracting one day
{% set tomorrow = today + day %}
{% set yesterday = today - day %}

//get any number of days before or after with multiplication: e.g.
{% set dayafterTomorrow = today + (2 * day) %}

//re-convert unix timestamp back to a date
{{ (dayafterTomorrow * 1000)|datetimeformat('%B %e, %Y') }}

 

 

Edit: Nevermind, @stefen's solutions is waaay better haha. I didn't know about the plus_time filter

 

stefen
Key Advisor | Partner
Key Advisor | Partner

Display date for each day of the week

SOLVE

@piersg I used to do something similar before the plus time filter was available. Either way works!

Stefen Phelps, Community Champion, Kelp Web Developer
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Display date for each day of the week

SOLVE

@ben-duchy there is a "plus_time" filter made specifically for this: https://developers.hubspot.com/docs/cms/hubl/filters#plus-time

 

It can be used in combination with the datetimeformat filter like so:

{{ content.updated|plus_time(1, 'days')|datetimeformat('%B %e, %Y') }}

 

Stefen Phelps, Community Champion, Kelp Web Developer
ben-duchy
Top Contributor

Display date for each day of the week

SOLVE

Hi @stefen,

 

Just to add to my original question...

 

I've managed to display a number based on the difference between a date selected within HubDB and todays date:

{% set end_days = (legal_completion - today)//24//60//60//1000 %}

 

Using {{ end_days }} days within my code shows '42 days' on the website and as todays date gets closer to the completion date, the number reduces.

 

However I now want to add days within this calculation for example 14 days using the below method, but it doesn't work!

{% set end_days = (legal_completion + 14 - today)//24//60//60//1000 %}

 

Any ideas what I need to do?

 

Thanks

0 Upvotes
piersg
Key Advisor

Display date for each day of the week

SOLVE

legal_completion and today are in unix time no? So adding 14 to them would be adding 14ms or something, not 14 days.

You could do:

 

{% set end_days = (legal_completion - today)//24//60//60//1000 %}
{% set end_days = end_days + 14 %}

OR

{% set end_days = (legal_completion + (86400 * 14) - today)//24//60//60//1000 %}

 

ben-duchy
Top Contributor

Display date for each day of the week

SOLVE

Hi @piersg,

 

I managed to find a solution... I was over thinking it!

 

The //24//60//60//1000 refers to the dates and so any addition needs to be placed after this (example below).

{% set res_exp_days = (reservation - today) //24//60//60//1000 + 14 %}

 

Thanks anyway

0 Upvotes
ben-duchy
Top Contributor

Display date for each day of the week

SOLVE

Thanks @stefen, thats exactly what I needed 👍

0 Upvotes