Calculate days difference between dates in Shopify Liquid templates

I’m working with Shopify liquid templates and need help with date calculations. I have two dates that I can retrieve:

{% assign item_launch_date = item.created_at | date: "%Y-%m-%d" %}
{% assign today_date = 'now' | date: "%Y-%m-%d" %}

This gets me today’s date and when my item was first created. What I want to do is show customers how many days ago the item was added to the store. I’ve looked through the liquid documentation but can’t figure out the right way to subtract these dates and get the number of days between them. Is there a way to do this math using only liquid syntax without any external scripts?

yep, it’s a bit tricky with liquid but here’s how: convert dates to unix timestamps using {% assign launch_unix = item.created_at | date: '%s' %} and {% assign now_unix = 'now' | date: '%s' %}. then just subtract them and divide by 86400 to get days: {% assign days_diff = now_unix | minus: launch_unix | divided_by: 86400 %}. hope that helps!

The unix timestamp approach works well, but don’t forget timezone considerations depending on your store setup. I’ve also used the date filter with %j (day of year) for same-year dates, but timestamps are way more reliable for cross-year calculations. Quick tip - if customers see this, round it or use floor so you don’t show weird partial days. Shopify’s liquid gets finicky with date math, so test everything thoroughly. I always check items created in previous years since that’s where things usually break.