• Créditos da HubSpot: Desbloqueie ferramentas poderosas para o crescimento

    Dúvidas?

How to format date property with HubL

Anders_Grové
Participante

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 Avaliação positiva
2 Solução aceitas
MBERARD
Solução
Top colaborador(a) | Parceiro Elite
Top colaborador(a) | Parceiro Elite

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

Exibir solução no post original

Anders_Grové
Solução
Participante

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!

Exibir solução no post original

0 Avaliação positiva
4 Respostas 4
MBERARD
Solução
Top colaborador(a) | Parceiro Elite
Top colaborador(a) | Parceiro Elite

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é
Solução
Participante

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 Avaliação positiva
MBERARD
Top colaborador(a) | Parceiro Elite
Top colaborador(a) | Parceiro Elite

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

0 Avaliação positiva
chighsmith
Gerente da Comunidade
Gerente da Comunidade

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 Avaliação positiva