Skip to content

Instantly share code, notes, and snippets.

@tongrhj
Created October 11, 2016 06:16
Show Gist options
  • Save tongrhj/04fa0495915b2bc5e8fe6a611875f292 to your computer and use it in GitHub Desktop.
Save tongrhj/04fa0495915b2bc5e8fe6a611875f292 to your computer and use it in GitHub Desktop.
Liquid Variable to calculate relative days left
<div><span style="font-size: 12px; color: #999999; line-height: 125%;">* {% if offer.expiry_date %}{% assign expiry_timestamp = (offer.expiry_date | date: '%s') %}{% assign now_timestamp = (now | date: '%s') %}{% assign seconds_apart = (expiry_timestamp | minus: now_timestamp) %}{% assign days_apart = (seconds_apart | divided_by: 86400 ) %}Current offer expires on {{ offer.expiry_date | date: '%-d %b %Y' }}<strong>{% if 2 &lt;= days_apart &lt;= 6 %} ({{ days_apart}} days left){% elsif days_apart == 1 %} (tomorrow){% else %} (today){% endif %}</strong>.{% endif %} Offers may change from time to time.</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment