Modify a date inside twig
3
When iterating over a DateTime object in PHP you have to make sure that you clone the date before you modify it since the modification does not return a new instance.
$date = new DateTime();
$date->add(new DateInterval('P1D'));
$newDate = clone $date;
$newDate->add(new DateInterval('P1D'));
In twig you cannot use the clone
keyword but you can use the date_modify twig filter.
{% set date = post.published_at %}
{% set newDate = date | date_modify("+1 day") }
There are no comments yet
Be the first one to comment