Date Filters

Date Filters

Use date filters to convert, manipulate, and display dates.

add_days

Return a date object operand days in the future. If operand is negative, return a date that many days in the past.

add_hours

Return a date object operand hours in the future. If operand is negative, return a date that many hours in the past.

add_minutes

Return a date object operand minutes in the future. If operand is negative, return a date that many minutes in the past.

add_months

Return a date object operand months in the future. If operand is negative, return a date that many months in the past.

add_seconds

Return a date object operand seconds in the future. If operand is negative, return a date that many seconds in the past.

add_weeks

Return a date object operand weeks in the future. If operand is negative, return a date that many weeks in the past.

add_years

Return a date object operand years in the future. If operand is negative, return a date that many years in the past.

date

Returns the current value as a date. If format is specified, converts the date to a string before returning it using the given format. format must be a valid standard or custom .NET date format. See the format filter below for some format string examples.

format

Returns the object formatted as a string using the provided format string. For numbers, the behavior is the same as the format_number filter. For time_diffs you must supply a valid standard or custom.NET TimeSpan format. For dates you must supply a valid standard or custom .NET date format.

format: format

{{request.date | format: "d"}}    9/9/2009
{{request.date | format: "D"}}    Sunday, September 9, 2009
{{request.date | format: "o"}}    2009-09-09T00:00:00.0000000Z
{{request.date | format: "MMMM dd, yyyy"}}    September 09, 2009

midnight

Return the date representing midnight for the current value

time_diff

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. format must be a valid standard or custom.NET TimeSpan format.

time_diff: date other, String format (optional)

{% var diff = request.date | add_days: 3 | time_diff: request.date %}
{{ diff.total_hours }} => 72
{{ request.date | add_days: 3 | time_diff: request.date, "g" }} => -3:0:00:00
{{ request.date | add_days: 3 | time_diff: request.date, "dd 'days'" }} => 03 days

timezone

Returns the timezone that the date is in. If full is true or if an abbreviated timezone name is not available, returns the full timezone identifier (eg: "Europe/Rome"). If full is false (default) or not specified and an abbreviated timezone name is available returns the abbreviated timezone name (eg: "PST" or "PDT").

timezone: full = false

{{request.date | timezone}}    EST
{{request.date | add_months: 6 | timezone}}    EDT
{{request.date | timezone: true}}    America/Indiana/Indianapolis

to_timezone

Converts the current date to the specified timezone.

to_timezone: String timezone

{{request.date | to_timezone: 'UTC'}}
{{request.date | to_timezone: 'Europe/Rome'}}