How to format date property with HubL

Anders_Grové
Participant

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 Upvotes
2 Accepted solutions
MBERARD
Solution
Top Contributor | Elite Partner
Top Contributor | 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

View solution in original post

Anders_Grové
Solution
Participant

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!

View solution in original post

0 Upvotes
4 Replies 4
MBERARD
Solution
Top Contributor | Elite Partner
Top Contributor | 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é
Solution
Participant

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 Upvotes
MBERARD
Top Contributor | Elite Partner
Top Contributor | Elite Partner

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

0 Upvotes
chighsmith
Community Manager
Community Manager

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 Upvotes