Skip to content

Date and time filters

A couple of filters for formatting and manipulating dates and time are included.

Info

In Lime, all the various types of dates and time properties, including specials like "year" and "quarter", are saved as full dates including time. That is why filters are needed to format the dates in relevant ways. Since date and time are technically the same, both might be referenced to as "date" in the documentation.

The formatting of dates is based on the locale set on the template in Lime Admin, which affects things such as the order of year-month-day, the names of days and months, and how weeks are counted. The locale can be overridden per filter call (see below).

Dates are rendered in the local time of the user generating the document. To render dates in a different timezone, change the timezone on the user's device before creating the document.

Manipulating

Sometimes a date needs to be manipulated. Several date manipulating filters can be piped.

Add years

add_years(years)

Adds years to the date. A negative value subtracts years. Example:

{{ deal.deadline | add_years(1) }}

Add months

add_months(months)

Adds months to the date. A negative value subtracts months. Example:

{{ deal.deadline | add_months(9) }}

Add weeks

add_weeks(weeks)

Adds weeks to the date. A negative value subtracts weeks. Example:

{{ deal.deadline | add_weeks(2) }}

Add days

add_days(days)

Adds days to the date. A negative value subtracts days. Example:

{{ deal.deadline | add_days(14) }}

Add hours

add_hours(hours)

Adds hours to the date. A negative value subtracts hours. Example:

{{ deal.deadline | add_hours(5) }}

Add minutes

add_minutes(minutes)

Adds minutes to the date. A negative value subtracts minutes. Example:

{{ deal.deadline | add_minutes(15) }}

Add seconds

add_seconds(seconds)

Adds seconds to the date. A negative value subtracts seconds. Example:

{{ deal.deadline | add_seconds(-30) }}

Formatting

Lime has several built in date properties, like date and time, time, week, quarter etc. All of these date properties should be piped through a filter. By piping these properties through a date filter, you can determine how they should be formatted/rendered and ensure that dates are rendered consistently across your whole document.

Almost all format filters have locale as an optional parameter which will override the template locale set in Lime Admin. Examples below are from a template with the locale set to Swedish (Sweden).

Warning

If no date formatting filter is applied, all types of date properties will be rendered similar to 1999-12-31 18:03:05+01:00

Date

Standard date.

format_date(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_date }}
1999-12-31

{{ deal.deadline | format_date(locale="en_US") }} (force US English)
12/31/1999

{{ deal.deadline | format_date(locale="da_DK") }} (force Danish)
31.12.1999

{{ deal.deadline | format_date(locale="zh_CN") }} (force Chinese)
1999/12/31

Date (short)

Short version of date.

format_date_short(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_date_short }}
fre 31 dec.

{{ deal.deadline | format_date_short(locale="en_US") }} (force US English)
Fri, Dec 31

{{ deal.deadline | format_date_short(locale="de_CH") }} (force Swiss German)
Fr., 31. Dez.

Date and time

Standard date with time. Options:

  • military: use 24 hour clock? Defaults to True
  • seconds: display seconds? Defaults to False
format_date_time(military=True, seconds=False, locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_date_time }}
1999-12-31 18:03

{{ deal.deadline | format_date_time(seconds=True) }} (display seconds)
1999-12-31 18:03:05

{{ deal.deadline | format_date_time(locale="en_US", military=False) }} (force US English, 12 hour)
12/31/1999 6:03 PM

{{ deal.deadline | format_date_time(military=False) }} (12 hour)
1999-12-31 6:03 em

Time

Time only. Options:

  • military: use 24 hour clock? Defaults to True
  • seconds: display seconds? Defaults to False
format_time(military=True, seconds=False, locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_time }}
18:03

{{ deal.deadline | format_time(seconds=True) }} (display seconds)
18:03:05

{{ deal.deadline | format_time(locale="en_US", military=False) }} (force US English, 12 hour)
6:03 PM

{{ deal.deadline | format_time(military=False) }} (12 hour)
6:03 em

Year

Year only.

format_year(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_year }}
1999

Quarter

Quarter. By default Q and a number is returned. If a locale is passed as an argument, a localized, sometimes not very commonly used, version is displayed.

format_quarter(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_quarter }} (default, no matter what locale is set on the template)
Q4

{{ deal.deadline | format_quarter(locale="sv_SE") }} (force Swedish, not so common)
K4

{{ deal.deadline | format_quarter(locale="en_US") }} (force US English)
Q4

Quarter (number)

Quarter, number only.

format_quarter_number(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_quarter_number }}
4

Month

Name of month.

format_month(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_month }}
december

{{ deal.deadline | format_month(locale="en_US") }} (force US English)
December

{{ deal.deadline | format_month(locale="de_AT") }} (force Austrian German)
Dezember

{{ deal.deadline | format_month(locale="nn_NO") }} (force New Norwegian)
desember

Month (short)

Short name of month.

format_month_short(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_month_short }}
dec.

{{ deal.deadline | format_month_short(locale="en_US") }} (force US English)
Dec

{{ deal.deadline | format_month_short(locale="de_AT") }} (force Austrian German)
Dez.

{{ deal.deadline | format_month_short(locale="nn_NO") }} (force New Norwegian)
des.

Week

ISO week number of year.

Warning

The locale parameter is deprecated and should not be used anymore. The filter only supports ISO week numbering and should not suggest different week numbers depending on locale. It is therefore not used for the formatting anymore and will eventually be removed.

format_week()

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_week }}
52

Day

format_day(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_day }}
fredag

{{ deal.deadline | format_day(locale="en_US") }} (force US English)
Friday

Day (short)

format_day_short(locale)

Example with 1999-12-31 18:03:05:

{{ deal.deadline | format_day_short }}
fre

{{ deal.deadline | format_day_short(locale="en_US") }} (force US English)
Fri

Custom pattern

Custom pattern to format date if the other filters do not provide what is needed. Locale aware.

format_date_pattern(pattern, locale)

Example with 2019-04-05 13:03:07:

{{ deal.deadline | format_date_pattern(pattern="y-MM-dd HH:mm:ss") }}
2019-04-05 13:03:07

Table with 2019-04-05 13:03:07 using different patterns:

Pattern Locale Result Comment
y-MM-dd HH:mm:ss sv_SE 2019-04-05 13:03:07
y-MM-dd HH:mm:ss en_US 2019-04-05 13:03:07
h:mm:ss a sv_SE 1:03:07 em
h:mm:ss a en_US 1:03:07 PM
hh:mm:ss a en_US 01:03:07 PM
H sv_SE 13 24 hour number
HH sv_SE 13 24 hour number with leading zero
h sv_SE 1 12 hour number
hh sv_SE 01 12 hour number with leading zero
m sv_SE 3 minute
mm sv_SE 03 minute with leading zero
s sv_SE 7 second
ss sv_SE 07 second with leading zero
a sv_SE em AM/PM
a en_US PM AM/PM
e sv_SE 5 day number of the week
e en_US 6 day number of the week
E sv_SE fre short day name
E en_US Fri short day name
EE en_US Fri short day name
EEE en_US Fri short day name
EEEE en_US Friday full day name
EEEEE en_US F first letter of the day
w sv_SE 14 week of the year
W sv_SE 1 week of the month
M en_US 4 month number
MM en_US 04 month number with leading zero
MMM en_US Apr short month name
MMMM en_US April full month name
MMMMM en_US A first letter of the month
Q en_US 2 quarter as number
QQ en_US 02 quarter as number with leading zero
QQQ en_US Q2 short name of quarter
QQQ sv_SE K2 short name of quarter
QQQQ en_US 2nd quarter full quarter name
y en_US 2019 year
yy en_US 19 year of the century
yyy en_US 2019 year
yyyy en_US 2019 year
'See you on' E 'at' h a'!' en_US See you on Friday at 1 PM! Mixed with single quoted strings

Piping

Some examples of how date manipulating and formatting filters can be piped.

Warning

Date manipulating filters must always precede formatting filters.

Example with 1999-12-31 18:03:05:

{{ deal.deadline | add_seconds(1) | format_time(seconds=True) }}
18:03:06

{{ deal.deadline | add_hours(5) | add_minutes(56) | add_seconds(56) | format_date_time(seconds=True) }}
1999-12-31 23:59:59

{{ deal.deadline | add_months(1) | format_month }}
januari

{{ deal.deadline | add_days(1) | format_month }}
januari

{{ deal.deadline | add_months(1) | add_days(1) | format_month }}
februari

{{ deal.deadline | add_months(1) | add_days(1) | format_month | upper }}
FEBRUARI