A few days ago the need to add variables in twig, to be precise having a date for example: 2016-01-04 I need to add 540 days for this I use the date_modify plugin present in twig.
To perform this operation you must perform the following:
{% In September modify = '540'%}
{% In September date = "now" | date ( "m / d / Y")%}
{{Date | date_modify ( "+" ~ ~ modify "day") | date ( "m / d / Y")}}
With this the result would be: 08/31/2017
Do you know another way?
{{ yourDate|date_modify("+1 day")|date("m/d/Y") }}
this code add 1 day to your date.
This worked for me:
{% set tomorrow = 'now'|date_modify("+1 day") %}
<input id="event_date" name="event_date" class="datepicker" type="date" value="{{ tomorrow|date('Y-m-d') }}" />
Just in case someone needs to add more than +1 day in a twig template
{% set sevenDays = date(yourDate)|date_modify("+7 days")|date("d/m/Y")%}
Once the variable set can be used anywhere in the template
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.