Skip to content

format datetime to a human form #42539

Answered by faizanakram99
W2AlharbiMe asked this question in Q&A
Discussion options

You must be logged in to vote

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 both datetime and datetime_immutable as carbon objects and all your datetime 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

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@W2AlharbiMe
Comment options

Answer selected by W2AlharbiMe
Comment options

You must be logged in to vote
1 reply
@W2AlharbiMe
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants