Print a date using Shopify's liquid syntax
Having trouble printing out a date in a proper format using Shopify's liquid templating language? Look no further.
The date formatter in liquid will take a timestamp and parse it out into a readable date depending on the format you enter. The syntax looks like this:
{{ timestamp | date: "%a, %b %d, %y" }}
This takes a variable called timestamp, passes it through the "date" liquid filter with the parameters "%a, %b %d, %y".
The parameters "%a, %b %d, %y" are the format of the parsed date. This means you can get it to print out different date formats by adjusting those values. For example: "%a, %b %d, %y" will print out something like: Fri, Jul 17, 21 (depending on your timestamp) whereas
{{ timestamp | date: "%Y" }}
Will output simply 2021. You can learn all about these formatting options here so that you can print out whatever format suits your website.
That's all there is to it! Just enter in a timestamp, pass in your formatting options and you've got a pretty date that you can use forever.