Filters

Liquid Date Filters

Date Filters

Liquid date filters format Shopify dates with date and time.

Introduction to Liquid Date Filters

Liquid date filters in Shopify are essential tools for formatting date and time values. They allow developers to transform raw date data into more readable and meaningful formats, which can enhance the user experience on your Shopify store. In this guide, we'll explore how to use these filters effectively.

Basic Date Filter Usage

The basic syntax for using a date filter in Liquid is to apply the filter to a date variable. Here's a simple example that formats a date variable into a more readable form:

In this example, {{ order.created_at }} is the date variable, and it is being formatted to display the full month name, day, and year (e.g., "October 21, 2023").

Common Date Formats

Liquid date filters support a variety of formatting options. Here are some commonly used date formats:

  • %d - Day of the month (01 to 31)
  • %m - Month (01 to 12)
  • %B - Full month name (e.g., January)
  • %y - Year without century (00 to 99)
  • %Y - Year with century (e.g., 2023)

Time Formatting

Apart from dates, Liquid date filters allow you to format time as well. You can include time components in your format string to display time in various ways. Here's an example:

This code will output the time in a 12-hour format with an AM/PM indicator, such as "02:30 PM".

Advanced Date Formatting

For more advanced formatting, you can combine multiple format specifiers. For instance, to display a complete timestamp, you might use:

This example combines the full weekday name, full month name, day, year, and time, resulting in a string like "Saturday, October 21, 2023 at 02:30 PM".

Handling Time Zones

By default, Liquid date filters output dates and times in UTC. To display dates and times in a specific time zone, you'll need to convert them manually, as Liquid does not support time zone conversion directly.

Consider using JavaScript or another method on the client side to adjust time zones according to your needs.

Conclusion

Liquid date filters are powerful tools within Shopify's templating language that allow for the flexible and readable display of date and time information. By mastering these filters, you can significantly enhance the presentation of temporal data on your Shopify store, providing a better experience for your customers.