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!