Get the time difference between two dates in Jekyll

I would like to get the difference in days between the two dates in Jekyll. How can I achieve this?

{% capture currentDate %}{{ site.time | date: '%Y-%m-%d' }}{% endcapture %}
{{currentDate}}
{% capture event_date %}{{ entry.date }}{% endcapture %}
{% if event_date < currentDate %}Yes{% else %}No{% endif %}

There is my YAML in the record:

---
title: ChartLine C3
type: charts
description: Chart with round for prisma
id: c3-1
date: 2015-07-18
--- 
+5
source share
4 answers

If all you want to do is know if the date from your Front Matter is earlier than the system time, then you can use the ISO 8601 date format and rely on lexicographic ordering. This is kind of a hoax, but it will work on the example you provided.

It is important that this trick works both as site.timewell as the date of your Front Matter ( page.past_dateand page.future_datein the example below) in ISO 8601 format.

---
layout: default
past_date: 2015-03-02
future_date: 2016-03-02
---

{% capture currentDate %}{{ site.time | date: '%F' }}{% endcapture %}
{% capture pastDate %}{{ page.past_date | date: '%F' }}{% endcapture %}
{% capture futureDate %}{{ page.future_date | date: '%F' }}{% endcapture %}
<br>currentDate: {{currentDate}}
<br>PastDate earlier than currentDate? {% if pastDate < currentDate %}Yes{% else %}No{% endif %}
<br>FutureDate earlier than currentDate? {% if futureDate < currentDate %}Yes{% else %}No{% endif %}

Gives me the following result:

currentDate: 2015-07-12

Is PastDate earlier than currentDate? Yes

FutureDate , currentDate?

+4

, .

, , 2000 :

{{ site.time | date: '%Y' | minus:2000 }}

, ... : https://github.com/markets/jekyll-timeago

, ( , )

+6

Liquid (Jekyll templating engine) :

{%   assign today = site.time | date: '%s'      %}
{%   assign start = '20-01-2014 04:00:00' | date: '%s'  %}
{%   assign secondsSince = today | minus: start     %}
{%   assign hoursSince = secondsSince | divided_by: 60 | divided_by: 60     %}
{%   assign daysSince = hoursSince | divided_by: 24  %}

Hours: {{hoursSince}}
Days: {{daysSince}}

: 27780

: 1157

, Liquid divide_by .

Remainder hours: {{hoursSince | modulo: 24}}

: 12

, , , :

{%   assign k = 10   %}
{%   assign divisor = 24   %}
{%   assign modulus = hoursSince | modulo: 24 | times: k | divided_by: divisor  %}
{{daysSince}}.{{modulus}}

1157,5

k, .

+6

, , :

{% assign currentYear = site.time | date: '%Y' %}
{% assign postYear = post.date | date: '%Y' %}
{% assign postAge = currentYear | minus: postYear | minus: 1 %}

{% if postAge >= 3 %}
<div class="maybe-obsolete">
  This post has been published more than {{ postAge }} years ago, and parts
  of its contents are very likely to be obsolete by now.
</div>
{% endif %}
0

All Articles