How to compare dates in Shopify?

Hura Product Showcase Builder

In Shopify, the dates are strings so you can’t compare strings in the usual way. With Shopify liquid, you have to use the %s date filter to convert the date time to Unix epoch time.

The following source code will convert a specific day:

The following source code will convert current date:

And now you can use the operators: >, <, >=, <=.

Hura Theme Blocks

You may also like...

2 Responses

  1. Luis says:

    Thank you very much. It’s great.

  2. Gary M says:

    I believe it is still comparing timestamp STRINGS so any timestamp that starts with an number higher than today’s timestamp, even if it’s 50 years ago, will always be greater than today. Suggestion to use a secondary filter, plus: 0, that coerces the timestamp to an integer.


    {% assign today_date = 'now' | date: '%s' % | plus: 0 }

Leave a Reply

Your email address will not be published. Required fields are marked *