format datetime to a human form #42539
-
Hello, i was wondering is there a function in twig like it should convert the datetime to this format:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
It's not a laravel function. It's part of carbon PHP package https://carbon.nesbot.com/ . You should be able to call See the docs I linked above, it has detailed guide about symfony integration. Also you can create twig extensions for stuff like converting datetime string to carbon objects (if needed) |
Beta Was this translation helpful? Give feedback.
-
you can try this package https://github.com/KnpLabs/KnpTimeBundle |
Beta Was this translation helpful? Give feedback.
It's not a laravel function. It's part of carbon PHP package https://carbon.nesbot.com/ .
You should be able to call
diffForHumans()
on any carbon object in PHP as well as twig. If you're using doctrine, register bothdatetime
anddatetime_immutable
as carbon objects and all yourdatetime
fields would be instances of Carbon.See the docs I linked above, it has detailed guide about symfony integration.
Also you can create twig extensions for stuff like converting datetime string to carbon objects (if needed)
https://symfony.com/doc/current/templating/twig_extension.html