Twig Time Difference Filter

Introduction

The Twig Time Difference Filter module provides a convenient and powerful Twig filter for Drupal sites, allowing developers to display human-readable time differences between two dates or the current time. This module is particularly useful for content that needs to show relative time differences, such as “2 days ago”, “3 months ago”, or “1 year ago”.

Features

  • Easy Integration: Simple to use in any Twig template.
  • Human-Readable Formats: Automatically formats time differences into a user-friendly string like “just now”, “5 minutes ago”, or “2 years ago”.
  • Flexible Input: Supports various date formats and automatically handles the current date if the end date is not provided.

Usage

Once enabled, you can use the time_diff filter in your Twig templates:

{% set start_date = '2023-01-01' %}
Time Difference: {{ start_date|time_diff }}

Or convert it from entity creation time like:

{{ node.created.value|time_diff }}

 

Ramsalt Norwegian Drupal Agency

Supporting organizations: 
Initial development and support

Project information

Releases