APIs & Integrations

joshm1
Member

How to Format value from Date Picker with Hubl Filter?

I am trying to use the “datetimeformat” filter on a contact field of the Date picker field type. The issue I’m having is the filter is not recognizing the value of the property as a datetime data type, which I’m assuming it requires in order to work properly.

Here is an example of how I’m using it trying to display the month:

{{ contact.appointment_date | datetimeformat('%B') }}

The value of {{ contact.appointment_date }} without any filtering displays as mm/dd/yyyy format.
I feel as though I can’t be the only one experiencing this issue but I cant find any documentation on it either.

Any help is appreciated.

Thank you,
Josh

0 Upvotes
4 Replies 4
Leonard0
Contributor | Diamond Partner
Contributor | Diamond Partner

How to Format value from Date Picker with Hubl Filter?

I had the same issue. I used 'date' instead of 'datetime'. The filter wasn't working in Design Manager. Tried to convert 'strtotime' and back to datetimeformat. However ...

{{ contact.appointment_date|datetimeformat('%B')}} does work, not in template preview but in a draft or a published page. When you set the time in CMS page edit mode, the datetime is set correctly from the date picker and the filter works. 


Did my answer solve your issue? Help the community by marking it as the solution.

0 Upvotes
rbharris1
Contributor

How to Format value from Date Picker with Hubl Filter?

It's been a few years, but I'm curious if either @tjoyce or @joshm1 have an update here. I have run into a similar issue.

This HubL code:

Screen Shot 2021-05-19 at 2.19.07 PM.png

Renders this:

Screen Shot 2021-05-19 at 2.19.18 PM.png

When I use  

{{ contact.date_of_birth_hs|datetimeformat('%m/%d/%Y') }}

I'm expecting to get 01/01/1945, but instead I get a blank.

Bob2245
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

How to Format value from Date Picker with Hubl Filter?

Same here. Documentation on this is horrible. It tells you to first apply "strtotime" for properties that aren't set as a datetime timestamp. Hubspot date picker properties, I believe, aren't datetime but date only. But the strtotime documentation is horrible as well. All it says is "Converts a datetime string and a datetime format into a datetime object." but that doesn't help me jack squat. 

 

I've got a date property referenced and just want to apply formatting to only show the year:

 

In Hubspot, it shows as: 1 jan. 1990

What I want to show in my template: "1990"

What I did:

{{ contact.mydatefield|datetimeformat("%Y") }} -> Gives blank

 

Frustrating.

 

 

 

 

tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

How to Format value from Date Picker with Hubl Filter?

I am also curious about this. I was debugging the datetime objects that Hubspot sets on blog posts and the raw output looks like this:

{% raw %}(PyishDate: 2017-03-28 12:40:45){% endraw %}```
0 Upvotes