Filters not working properly?

I have a Date Picker Property (enrollment_date), that I’m trying to use to calculate dates inside emails.
My first try was to use it directly:
{% set future_date_1 = contact.enrollment_date|plus_time(3, ‘days’) %}
Which doesn’t work because the plus_time requires a datetime object, and the datepicker apparently returns a string (Issue 1):
{{ contact.enrollment_date|pprint }}

(String: 5/1/23)
Because of that, I’ve tried to use strtotime, but I found that unless I pass the entire format, it won’t work properly (Issue/bug 2).
For example this doesn’t work:

{% set enrollment_date_datetime = contact.enrollment_date|strtotime(“M/d/yy”) %}
So in order for me to create a string with the entire date in the right format, I’ll have to first use something like this:

{% set enddate = (date_parts[2] + “-” + date_parts[0] + “-” + date_parts[1] + “T14:31:30+0530”)|strtotime(“yyyy-MM-dd’T’HH:mm:ssZ”) %}
However, in order to do that, I need to get the parts from my date, and when trying the following, I’m not being able to do so:
(Issue/Bug 3). Seems like the SPLIT filter is not working on the type of sting that is returned by the datepicker property, even though the pprint is saying that is a string

Example for context. The Following is parsed correctly:

{% set date_string = “5/1/23” %}
{% set date_parts = date_string|split(‘/’) %}

Day: {{ date_parts[1] }}
Month: {{ date_parts[0] }}
Year: {{ date_parts[2] }}

Result:

Day: 1
Month: 5
Year: 23

---- The Following is parsed incorrectly:

{% set date_string = contact.enrollment_date %}
{% set date_parts = date_string|split(‘/’) %}

Day: {{ date_parts[1] }}
Month: {{ date_parts[0] }}
Year: {{ date_parts[2] }}

Result:
Day:
Month: 5/1/23
Year:

---- This is also parsed incorrectly

{% set date_string = contact.enrollment_date|string %}
{% set date_parts = date_string|split(‘/’) %}
{% set date_parts = date_parts[0]|split(‘/’) %}

Day: {{ date_parts[1] }}
Month: {{ date_parts[0] }}
Year: {{ date_parts[2] }}

Result:
Day:
Month: 5/1/23
Year:

Other alternatives that I’ve tried unssuccessfully:

---- This is also parsed incorrectly (Added STRING filter multiple times)

{% set date_string = contact.enrollment_date|string %}
{% set date_parts = date_string|string|split(‘/’) %}
{% set date_parts = date_parts[0]|string|split(‘/’) %}

Day: {{ date_parts[1] }}
Month: {{ date_parts[0] }}
Year: {{ date_parts[2] }}

Result:
Day:
Month: 5/1/23
Year:

---- This is also parsed incorrectly

{% set date_string = contact.enrollment_date|date(‘%m/%d/%y’) %}
{% set date_parts = date_string|split(‘/’) %}
Day: {{ date_parts[1] }}
Month: {{ date_parts[0] }}
Year: {{ date_parts[2] }}

Result:

Day:
Month:
Year:

---- This is also parsed incorrectly

{% set date_string = contact.enrollment_date %}
{% set date_parts = date_string|regex_findall(‘\d+’) %}
Day: {{ date_parts[1] }}
Month: {{ date_parts[0] }}
Year: {{ date_parts[2] }}

Result:

Day:
Month:
Year:

I’d appreciate your help to try to debug this.
Understanding that returning the date picker as a string can’t be changed, the ideal outcome would be to solve Issue 2, to make the following work:
{% set enrollment_date_datetime = contact.enrollment_date|strtotime(“M/d/yy”) %}
And as a last resource, see why the string that is returned can’t be split by the split filter correctly.
Thanks!

Hi @sdanessa,

From the docs: HubL filters - HubSpot docs

Please note: you can apply HubL filters to personalization tokens, such as contact and company tokens, on HubSpot CMS and blog pages, but not in emails.


I think this is the main source of your issues here. As a work around I would try formatting the property using a workflow and copying that to another property, and using that vlaue directly within the email.

Best,

Thanks so much, Joshua!
I totally missed that line of the docs.
Your workflow idea makes sense, although I think it will be a bit convoluted for this particular use case, since there are quite a few other dates to calculate.
Can you by any chance think of some function that brings the value of the property earlier, that is available inside emails, so I can copy only the value, and operate on that string inside the email, instead?
I’ve tried with this, after reading your message:
{% set date_string2 = personalization_token(“contact.enrollment_date”, “1/1/23”) %}
but it’s also not filterable.
I imagine bc it’s processed later in the code.
Cheers!

In my testing around programmable emails any time a variable touches anything related to a pesronalization token, all the stuff touching that variable stops working. So I do not know of any work arounds here.

Best,

Thanks again, Joshua.