Sometime we want to show the product publish date on product template.
Here is the code to show product created and publish date on product page.
1) product.published_at :- Returns the date and time the product was published.
2) product.created_at :- Returns the date and time the product was created
For example:- I want to show the NEW badge on product pages which one are published less than 15 days ago.
{% assign product_pub_at = product.published_at | date: '%s' %}
{% assign time_ago = 'now' | date: '%s' | minus: product_pub_at | divided_by: 86400 %}
{% if time_ago < 15 %}
<div class="new_banner prd">NEW</div>
{% endif %}
For products added in the last 15 days or you can modify the days in coding.
I hope this helps you ..
Thanks 🙂
Thanks a lot for your great help! Narender is the expert!
Thanks 🙂