Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add days to a variable date in twig

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?

like image 504
juanitourquiza Avatar asked Nov 29 '16 19:11

juanitourquiza


1 Answers

{{ yourDate|date_modify("+1 day")|date("m/d/Y") }}

this code add 1 day to your date.

see http://twig.sensiolabs.org/doc/filters/date_modify.html

like image 60
abhinand Avatar answered Sep 24 '22 02:09

abhinand