I am trying to calculate a difference in days between (a) the date a Webform was completed and (b) an "Event Date" field on the Webform. I have added a Computed Twig field to the webform and attempted to use this code (similar to https://stackoverflow.com/a/27205095/1357555):
{% set difference = date(data.event_date).diff(date(completed)) %}
{% set leftDays = difference.days %}
However, I am getting an error message when attempting to save the field.
Computed value/markup is not valid.
- Calling "diff" method on a "DateTime" object is not allowed in "{# inline_template_start #}{{ completed|date }} {{ data.date_needed|date }} {% set difference = date(data.event_date).diff(date(completed)) %} {% set leftDays = difference.days %}" at line 4.
Failed to render computed Twig value due to error.
{% set difference = data.date_needed|date('U') - completed %}
to find the difference based on Unix time. Then{% set leftDays = (difference / 60 / 60 / 24)|round(0, 'ceil') %}
to get a "number of days" value.