DanWebb
10/13/2015 - 2:48 PM

Display whether a product or is new or not. Could also apply to other objects that have the created_at property.

Display whether a product or is new or not. Could also apply to other objects that have the created_at property.

{% comment %}

Get the unix time between today and the date the product was created. 
If there's less than 30 days (2592008) between the two times display it as new.

Note: "times: 1" is used to make sure the timestamp is an int not a string

Example usage: 
	{% include 'new_item' with product %}

{% endcomment %}

{% assign created = new_item.created_at | date: '%s' | times: 1 %}
{% assign today = 'now' | date: '%s' | times: 1 %}

{% assign time_diff = today | minus: created %}

{% if time_diff <= 2592008 %}
<h1>This item is less than a 30 days old</h1>
{% endif %}