date

v1.9.1

Format

  • Converts a timestamp into another date format
  • LiquidJS tries to be conformant with Shopify/Liquid which is using Ruby’s core Time#strftime(string)
  • The input is firstly converted to Date object via new Date()
  • Date format can be provided individually as a filter option
    • If not provided, then %A, %B %-e, %Y at %-l:%M %P %z format will be used as default format
    • Override this using dateFormat LiquidJS option, to set your preferred default format for all date filters

Examples

{{ article.published_at | date: '%a, %b %d, %y' }} => Fri, Jul 17, 15
{{ "now" | date: "%Y-%m-%d %H:%M" }} => 2020-03-25 15:57

// equivalent to setting options.dateFormat = %d%q of %b %Y at %I:%M %P %Z
{{ '1990-12-31T23:30:28Z' | date: '%d%q of %b %Y at %I:%M %P %Z', -330 }} => 01st of Jan 1991 at 05:00 am +0530;

TimeZone

  • By default, dates will be converted to local timezone before output
  • You can override that by,
    • setting a timezone for each individual date filter via the second parameter
    • using the timezoneOffset LiquidJS option
      • Its default value is your local timezone offset which can be obtained by new Date().getTimezoneOffset()
      • Offset can be set as,
        • minutes: -360 means '+06:00' and 360 means '-06:00'
        • timeZone ID: Asia/Colombo or America/New_York
      • Use minutes for better performance with repeated processing of templates with many dates like, converting template for each email recipient
    • Refer here for TZ database values

Examples

// equivalent to setting `options.timezoneOffset` to `360`
{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360 }} => 1990-12-31T17:00:00
{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", "Asia/Colombo" }} => 1991-01-01T04:30:00

Input

Examples

{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360 }} => 1990-12-31T17:00:00
{{ "March 14, 2016" | date: "%b %d, %y" }} => Mar 14, 16

Current Date

  • To get the current time, pass the special word "now" or "today" as input
  • Note that the value will be the current time of when the page was last generated from the template, not when the page is presented to a user if caching or static site generation is involved

Example

Last updated on: {{ "now" | date: "%Y-%m-%d %H:%M" }} => Last updated on: 2020-03-25 15:57
Last updated on: {{ "today" | date: "%Y-%m-%d %H:%M" }} => Last updated on: 2020-03-25 15:57