Knplabs time bundle makes your dates look sensible and descriptive

Installs: 2 150 944

Dependents: 29

Suggesters: 2

Security: 0

Stars: 435

Watchers: 38

Forks: 92

Open Issues: 10


v1.13.0 2020-08-14 14:19 UTC


This bundle does one simple job: takes dates and gives you friendly "2 hours ago"-type messages. Woh!

Last edited {{ post.updatedAt|ago }}
<-- Last edited 1 week ago -->

Want to see it used in a screencast 🎥? Check out SymfonyCasts:

The date formatted can be translated into any language, and many are supported out of the box.


Use Composer to install the library:

composer require knplabs/knp-time-bundle

Woo! You did it! Assuminy project uses Symfony Flex, the bundle should be configured and ready to go. If not, you can enable Knp\Bundle\TimeBundle\KnpTimeBundle manually.


In Twig!

{{ someDateTimeVariable|ago }}

... or use the equivalent function
{{ time_diff(someDateTimeVariable) }}

In controllers

You can also "ago" dates inside PHP by autowiring the Knp\Bundle\TimeBundle\DateTimeFormatter service:

use Knp\Bundle\TimeBundle\DateTimeFormatter;
// ...

public function yourAction(DateTimeFormatter $dateTimeFormatter)
    $someDate = new \DateTime('2017-02-11'); //or $entity->publishedDate()
    $now = new \DateTime();
    $agoTime = $dateTimeFormatter->formatDiff($someDate, $now);
    return $this->json([
        'published_at' => $agoTime


If you want to run tests, please check that you have installed dev dependencies.



Anyone can contribute to this repository (and it's warmly welcomed!). The following people maintain and can merge into this library: