Display remaining days left and then "Closed" when it reaches 0 using Liquid

148 views Asked by At

I currenty have data in my CMS which outputs this on the front end:

2017-03-16T00:00:00

What I like this to do is check the above date and see how many days is left to that day and display it as: 7 days left (assuming today is the 9th March 2017)

And then when the date reaches 0, it needs to display the text: "Closed"

Currently I have:

{% assign todaysdate = {{todaysdate]}} %}               
{% assign todaysdatenew = todaysdate | convert: "date" %}
{% assign formula = {{globals.site.dateNow}} | minus: todaysdatenew %}  
{% if {{globals.site.dateNow}} > todaysdatenew %}
    Closed
{% else %}
    {{formula | date:"%d' days'"}}
{% endif %}

However for some reason it is displaying the result as 6 days left, instead of 7 days left. How do I add 1 extra day?

1

There are 1 answers

0
Deanmv On

If it is always one day then you can change just hardcode add the extra day by editing the line below:

{{formula | date:"%d' days'"}}

To:

{% assign formulaResult = {{formula | date:"%d' days'"}} -%}
{{formulaResult | date_add: 1, "day"}}