How to format a date ?


This how to will show you how to format a date with the pipeline format function.

You can apply it to any date variable such as:


Today's date

Without any formatting, the date is given in the iso date format



To apply a formatting, you need to use the format function

${now | format()}

The output is a date formatted to the default format of your locale (ie country and language)

Friday, June 7, 2024

To have it refresh every day, we expire the page cache date daily

Today's date with a pattern

Today's date with a date pattern where:

  • MMM is the short month description
  • dd is the day number on two digits
${now | format( "MMM dd" )}
  • The output:

Jun 07

Formatting a date content

Because a pipeline is an expression, you can even format a date written in your content.

${"2022-05-05" | format()}
  • The output:

Thursday, May 5, 2022

Formatting a date in an other language

  • A date formatted in French with the default pattern (The markup with the locale attribute with just the region (ie country) as value)
${now | format( "", "fr" )}

vendredi 7 juin 2024

  • Compare it with the US date
${now | format( "", "us" )}

Friday, June 7, 2024

Date of a page

You can also print the date metadata of a page.

For instance, for the date of this article

  * ${date_created | format()}
  * ${date_modified | format()}
  * ${date_published | format()}

The output is:

  • Monday, April 17, 2023
  • Monday, April 17, 2023
  • Sunday, September 26, 2021

Showcase yourself and your brand

Get free news, tips, and tricks
to create a remarkable experience for your readers.

Recommended Pages
Undraw Building Websites I78t
ComboStrap Pipeline

A pipeline permits to transform a variable value with a succession of transformation function.
Undraw File Analysis 8k9b
Which date format are supported

How to write a date in the frontmatter to be valid

Task Runner