How to format date property with HubL

Anders_Grové
参加者

I am looking for a working example of the format_date or format_datetime filters.

 

The problem:

 

I want to display just the day of a datetime property. We used to be able to do this with the deprecated filter |datetimeformat("%d"). Now we have the new |format_datetime filter - but nothing I try can make this work.

 

The only working example I could find was on the blog template of the Elevate theme in HubSpot github:

 

 

{{ content.publish_date|format_date('long') }}

 

 

But when I used pprint to check this property type it showed that the blog date type is actually:

 

 

(PyishDate: 2025-05-19 22:00:00)

 

 

The datetime type properties we get from crm records are string type, which seems to me like the issue. Is there a parse function that converts to PyishDate type - not finding anything on this...

 

I am looking for a pure HubL solution, I'm aware you can do this with javascript.

 

Anyone have a clue?

 

 

0 いいね!
2件の承認済みベストアンサー
MBERARD
解決策
トップ投稿者 | Elite Partner
トップ投稿者 | Elite Partner

Hi @Anders_Grové ,

Since you’re getting a string instead of a Date object, the filter can’t properly convert the date.

What I’d suggest is applying the strtotime filter first, and then formatting your date.


Best regards.

 

Matthieu BERARD

元の投稿で解決策を見る

Anders_Grové
解決策
参加者

Ah such an easy solve, didn't spot that filter. Thank you!

 

BTW, I also found another solution by adding a 'false' parameter on the crm_objects function.

 

Community FTW!

元の投稿で解決策を見る

0 いいね!
4件の返信 4
MBERARD
解決策
トップ投稿者 | Elite Partner
トップ投稿者 | Elite Partner

Hi @Anders_Grové ,

Since you’re getting a string instead of a Date object, the filter can’t properly convert the date.

What I’d suggest is applying the strtotime filter first, and then formatting your date.


Best regards.

 

Matthieu BERARD

Anders_Grové
解決策
参加者

Ah such an easy solve, didn't spot that filter. Thank you!

 

BTW, I also found another solution by adding a 'false' parameter on the crm_objects function.

 

Community FTW!

0 いいね!
MBERARD
トップ投稿者 | Elite Partner
トップ投稿者 | Elite Partner

Good to know about the crm_objects function — thanks for sharing!
Happy coding!

0 いいね!
chighsmith
コミュニティーマネージャー
コミュニティーマネージャー

Hi @Anders_Grové,

Thank you for posting to the Community!

I understand that you’re having trouble displaying just the day from a datetime property in HubL using the new format_date or format_datetime filters, since CRM record datetime properties are strings rather than PyishDate objects, and you’re seeking a pure HubL solution for parsing and formatting these values.

I'd like to tag in some of our Top Contributors to see if they have any advice here -- Hi @MBERARD @Stephanie-OG and @Indra Do any of you have any tips or tricks for @Anders_Grové?

Thank you!

Cassie, Community Manager

 

 





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 いいね!