Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DateTime and DateInterval functions in Twig

I have two objects in Twig:

  1. {{ date }} is DateTime object
  2. {{ interval }} is DateInterval object

I need to show date with interval added. How can I use DateObject php function like add() with this two objects?
I can't do this on controller side, I need interval to date in twig. :(

like image 359
user2279871 Avatar asked Nov 28 '25 12:11

user2279871


1 Answers

You can use date_modify.

In your case, it would go as:

{{ yourDate|date_modify(yourInterval)|date("m/d/Y") }}
like image 103
cheesemacfly Avatar answered Dec 01 '25 19:12

cheesemacfly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!