Time Diff

Time Diff

{{ time_diff }}

Contains information about the difference between two dates.

Name Type Description
is_valid Boolean Will always be true
days Integer The number of days between the two dates
hours Integer The hours component of the difference between the two dates (eg: if the dates are 25 hours apart this will be 1 since they are 1 day and 1 hour apart)
minutes Integer The minutes component of the difference between the two dates (eg: if the dates are 90 minutes apart this will be 30 since they are 1 hour and 30 minutes apart)
seconds Integer The seconds component of the difference between the two dates (eg: if the dates are 70 seconds apart this will be 10 since they are 1 minute and 10 seconds apart)
total_days Number The total difference between the two dates expressed as whole and fractional days (eg: 25 hours apart would be 1.042 days)
total_hours Number The total difference between the two dates expressed as whole and fractional hours (eg: 1 day and 90 minutes apart would be 25.5 hours)
total_minutes Number The total difference between the two dates expressed as whole and fractional minutes (eg: 90 minutes, and 10 seconds apart would be 90.167 minutes)
total_seconds Number The total difference between the two dates expressed as whole and fractional seconds (eg: 122 seconds and 10 milliseconds apart would be 122.1 seconds)
output String The time diff represented as a string using the standard "constant" format ([-][d.]hh:mm:ss[.fffffff] where all portions of the format in brackets are only included when needed)

time_diff filter

If format is unspecified, returns a time_diff object describing the difference between the current date and the other date. If format is specified, converts the time difference to a string before returning it using the given format. If supplied, the format must be a valid standard or custom.NET TimeSpan format.

time_diff: time otherString format

Examples

Format time diffs using standard or custom.NET TimeSpan formats.

Format Time Diffs

Copy
{% var diff = request.date | add_days: 3 | time_diff: request.date %}
{{ diff | format: "g" }}
{{ diff | format: "dd 'days'" }}

Time diff

Copy
{% var diff = request.date | time_diff: calendarEntry.start_date %} {% var is_future = true %} {% if diff.total_seconds < 0 %} {% set is_future = false %} {% endif %} This event {% if is_future %}will start in{% else %}started{% endif %} {% if diff.days > 0 %}{{diff.days }} days{% endif %} {% if diff.hours > 0 %}{{diff.hours }} hours{% endif %} {% if diff.minutes > 0 %}{{diff.minutes }} minutes{% endif %} {% if diff.hours == 0 and diff.seconds > 0 %}{{diff.seconds }} seconds{% endif %} {% unless is_future %}ago{% endunless %}

Examples

Time diff

Copy
{% var diff = request.date | time_diff: calendarEntry.start_date %} {% var is_future = true %} {% if diff.total_seconds < 0 %} {% set is_future = false %} {% endif %} This event {% if is_future %}will start in{% else %}started{% endif %} {% if diff.days > 0 %}{{diff.days }} days{% endif %} {% if diff.hours > 0 %}{{diff.hours }} hours{% endif %} {% if diff.minutes > 0 %}{{diff.minutes }} minutes{% endif %} {% if diff.hours == 0 and diff.seconds > 0 %}{{diff.seconds }} seconds{% endif %} {% unless is_future %}ago{% endunless %}

Format time diffs using standard or custom.NET TimeSpan formats.

Format Time Diffs

Copy
{% var diff = request.date | add_days: 3 | time_diff: request.date %}
{{ diff | format: "g" }}
{{ diff | format: "dd 'days'" }}