Date filters

duration

Return a date a certain number of days from another date.

Input

{{ "2023-05-11" | duration(5) }}

Output

2023-05-16T00:00:00.000+01:00

A second parameter can be used to change the unit used to increment the date by. Accepts "days", "weeks", "months" or "years". Default is "days":

Input

{{ "2023-05-11" | duration(5, "weeks") }}
{{ "2023-05-11" | duration(5, "months") }}
{{ "2023-05-11" | duration(5, "years") }}

Output

2023-06-15T00:00:00.000+01:00
2023-10-11T00:00:00.000+01:00
2028-05-11T00:00:00.000+01:00

To return a date from today’s date, pass the special word "today" (or "now"):

Input

{# Current datetime is 2023-05-06T09:00:59 #}
{{ "today" | duration(5) }}

Output

2023-05-11T09:00:59

govukDate

Convert an ISO 8601 date time into a human readable date that follows the GOV.UK style.

Input

{{ "2021-08-17" | govukDate }}

Output

17 August 2021

You can also output a date with a truncated month:

Input

{{ "2021-08-17" | govukDate("truncate") }}

Output

17 Aug 2021

To get the today’s date, pass the special word "today" (or "now"):

Input

This page was last updated on {{ "today" | govukDate }}.

Output

This page was last updated on 22 October 2021.

govukTime

Format an ISO 8601 date time or time to a human readable time that follows the GOV.UK style.

Input

{{ "2021-08-17T00:00:31" | govukTime }}
{{ "2021-08-17T12:00:59" | govukTime }}
{{ "2021-08-17T18:30:00" | govukTime }}

Output

midnight
midday
6:30pm

You can also pass in a time:

Input

{{ "08:15" | govukTime }}

Output

8:15am

To get the current time, pass the special word "now" (or "today"):

Input

You submitted your application at {{ "now" | govukTime }}.

Output

You submitted your application at 4:32pm.

isoDateFromDateInput

The govukDateInput component stores separate values for day, month and year values.

When prefixed using a namePrefix, these values are stored with names prefixed with that value. This filter takes these prefixed values and converts them into an ISO 8601 formatted date.

Input

const data = {
  `dob-day`: '01',
  `dob-month`: '02',
  `dob-year`: '2012',
}
{{ data | isoDateFromDateInput("dob") }}

Output

2012-02-01

Combine this filter with govukDate to output a human readable date:

Input

{{ data | isoDateFromDateInput("dob") | govukDate }}

Output

1 February 2012

It’s possible to configure govukDateInput so that only certain parts of a date are asked for, such as a month and year. You can also omit the namePrefix option and use individual name options for each value if you want to save them in a nested object. This filter covers that use case:

Input

const data = {
  passport: {
    month: '5',
    year: '2001',
  }
}
{{ data.passport | isoDateFromDateInput }}

Output

2001-05

monthName

Convert a number (between 1 and 12) into the name of the corresponding month.

Input

{{ 3 | monthName }}

Output

March

You can also output a truncated month name:

Input

{{ 3 | monthName("truncate") }}

Output

Mar