Twig date difference
问题 I've got an entity with a starting date and an ending date. Is it possible to get the difference in time between them by using twig? 回答1: Since PHP 5.3 There is another option without to write an extension. This example show how to calc the plural day/days {# endDate and startDate are strings or DateTime objects #} {% set difference = date(endDate).diff(date(startDate)) %} {% set leftDays = difference.days %} {% if leftDays == 1 %} 1 day {% else %} {{ leftDays }} days {% endif %} Explanation: