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.

  • 1
    This doesn't really answer my question, but here's my workaround: {% 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.
    – MrPeanut
    Apr 26, 2018 at 14:32

1 Answer 1


This is a bug in the Webform module. I created the below ticket to address this issue.

Improve Computed Twig element validation to support complex calculations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.