date
Converts a timestamp into another date format.
The date
filter accepts the same parameters as Ruby's strftime method for formatting the date. For a list of shorthand
formats, refer to the Ruby documentation or
strftime reference and sandbox.
{{ article.created_at | date: '%B %d, %Y' }}
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}
Output
The current date
You can apply the date
filter to the keywords 'now'
and 'today'
to output the current timestamp.
The timestamp will reflect the time that the Liquid was last rendered. Because of this, the timestamp might not be updated for every page view, depending on the context and caching.
{{ 'now' | date: '%B %d, %Y' }}
Output
format
Specify a locale-aware date format. You can use the following formats:
basic
date
default
short
(deprecated)long
(deprecated)
You can also define custom formats in your theme's locale files.
{{ article.created_at | date: format: 'abbreviated_date' }}
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}
Output
Setting format options in locale files
You can define custom date formats in your theme's storefront locale files. These custom formats should be included in a category:
{{ article.created_at | date: format: 'month_day_year' }}
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}