Recent searches
No recent searches
Comparing User Field Date to Today (Liquid question)
Posted Sep 06, 2024
I am trying to write Liquid logic into a trigger to compare today's date to a custom user field date. Use case is that I am setting up user fields to allow users to specify a start and end date to their OOO, to send a different autoresponse if the assignee has specific their OOO date.
I added a custom user field of a date type. I then read multiple places to do a "plus 0" which will convert the date to a string. I then do the same for current date. My two variables give the correct response, for example ooostart provided 2024090700 for a date of 09-07-2024 and current_date provided 2024090620. I then tried to write logic to compare them, “ooostart <= current_date
” but it always gives a true response, even if it is not true; in fact, both ooostart <= current_date
and ooostart > current_date
give true responses. No matter what I do, the comparison logic is always true.
Why would the logic be failing? I found multiple generic Liquid posts online about comparing date fields and all show this method, but it doesnt seem to be working in Zendesk for some reason. I thought maybe its because the first variable isnt a number, but the “plus: 0” for both variables should be fixing that.
My code:
{% assign ooostart = ticket.assignee.custom_fields.start_date | date: "%Y-%m-%d %H:%M" | remove: '-' | remove: ' '| plus: 0 %}
{{ ooostart }}
{% assign current_date = "now" | date: "%Y-%m-%d %H:%M" | remove: '-' | remove: ' ' | plus: 0 %}
{{ current_date }}
{% if ooostart <= current_date %}OOO has started{% else %}OOO has not started{% endif %}
0
0 comments