APIs & Integrations

Anonymous
Not applicable

Display Date and Time on Page from hubDB

SOLVE

I'm storing the time_zone of the datestamp in a hubDB table.

I need to display the date and time with the correct zone that the user is currently in

 

Need:

Start Date/Time: {{ row.time_start|datetimeformat("%B %e, %Y, %I:%M %p %Z",{{users_current.time_zone???}}

) }}

 

Works:

Start Date/Time: {{ row.time_start|datetimeformat("%B %e, %Y, %I:%M %p %Z",{{row.time_zone}}) }}

 

Works:

Start Date/Time: {{ row.time_start|datetimeformat("%B %e, %Y, %I:%M %p %Z","America/Chicago") }}

0 Upvotes
1 Accepted solution
BarryGrennan
Solution
Top Contributor

Display Date and Time on Page from hubDB

SOLVE

So 

 

{{ to_local_time(row.time_start) }} 

 

will convert your row.time_start to local time.

But there's probably a step missing here because I assume your "row.time_zone" represents the time zone the event is in, yes?

Assuming row.time_start is a standard date time input field, that'll be UTC, so the above would take that time to be UTC and convert it to local.

You likely need to figure out the difference between UTC time to the time in row.time_zone first.


If that's the case, I think this should work:

 

{# UTC to Local #}
 {% set base_time = row.time|datetimeformat("%Y-%m-%dT%H:%M:%S+0000",row.time_zone) %}

{# UNIX for UTC #}
{% set unix = row.time|unixtimestamp %}

{# UNIX for "UTC to Local" #}
{% set unix_ev = base_time|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}

{# Difference #}
{% set difference = unix_ev - unix %}

{# Unix minus difference #}
{% set unix_minus = unix - difference %}

{# Local Time of Event #}
{{ to_local_time(unix_minus) }} 

 

 

I'm not too sure if the difference field gets messed up if the event timezone is on the "other" side of UTC if you get my meaning, but it's late and I've obsessively tinkered with this for way too long 😂

Feel free to play around with it and let me know if it works and if you figure out any improvements!

And apologies if some of my labels up there are confusing, timey wimey stuff melts my head!


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

 

View solution in original post

5 Replies 5
BarryGrennan
Solution
Top Contributor

Display Date and Time on Page from hubDB

SOLVE

So 

 

{{ to_local_time(row.time_start) }} 

 

will convert your row.time_start to local time.

But there's probably a step missing here because I assume your "row.time_zone" represents the time zone the event is in, yes?

Assuming row.time_start is a standard date time input field, that'll be UTC, so the above would take that time to be UTC and convert it to local.

You likely need to figure out the difference between UTC time to the time in row.time_zone first.


If that's the case, I think this should work:

 

{# UTC to Local #}
 {% set base_time = row.time|datetimeformat("%Y-%m-%dT%H:%M:%S+0000",row.time_zone) %}

{# UNIX for UTC #}
{% set unix = row.time|unixtimestamp %}

{# UNIX for "UTC to Local" #}
{% set unix_ev = base_time|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}

{# Difference #}
{% set difference = unix_ev - unix %}

{# Unix minus difference #}
{% set unix_minus = unix - difference %}

{# Local Time of Event #}
{{ to_local_time(unix_minus) }} 

 

 

I'm not too sure if the difference field gets messed up if the event timezone is on the "other" side of UTC if you get my meaning, but it's late and I've obsessively tinkered with this for way too long 😂

Feel free to play around with it and let me know if it works and if you figure out any improvements!

And apologies if some of my labels up there are confusing, timey wimey stuff melts my head!


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

 

Jaycee_Lewis
Community Manager
Community Manager

Display Date and Time on Page from hubDB

SOLVE

You're a legend, @BarryGrennan! Thank you very much 🙌 — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

BarryGrennan
Top Contributor

Display Date and Time on Page from hubDB

SOLVE

Now worries. Cheers @Jaycee_Lewis 🙂

0 Upvotes
Anonymous
Not applicable

Display Date and Time on Page from hubDB

SOLVE

Awesome. Thank you

Jaycee_Lewis
Community Manager
Community Manager

Display Date and Time on Page from hubDB

SOLVE

Hi, @Anonymous 👋 Thanks for reaching out! Hey, @BarryGrennan @Chris-M @piersg, can you help @Anonymous with their goal? 

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes