APIs & Integrations

Anonymous
適用対象外

Display Date and Time on Page from hubDB

解決

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 いいね!
1件の承認済みベストアンサー
BarryGrennan
解決策
トップ投稿者

Display Date and Time on Page from hubDB

解決

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

 

 

 

元の投稿で解決策を見る

5件の返信
BarryGrennan
解決策
トップ投稿者

Display Date and Time on Page from hubDB

解決

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
コミュニティーマネージャー
コミュニティーマネージャー

Display Date and Time on Page from hubDB

解決

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

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

BarryGrennan
トップ投稿者

Display Date and Time on Page from hubDB

解決

Now worries. Cheers @Jaycee_Lewis 🙂

0 いいね!
Anonymous
適用対象外

Display Date and Time on Page from hubDB

解決

Awesome. Thank you

Jaycee_Lewis
コミュニティーマネージャー
コミュニティーマネージャー

Display Date and Time on Page from hubDB

解決

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 いいね!