Get Today's Date in Jekyll with Liquid Markup

Get today's date in Jekyll with Liquid markup

It didn't work for me either. It appears you've hit a current bug in the Ruby 1.9.3 support. There is a pull request that fixes the bug, but it's not incorporated yet. A workaround is listed, perhaps it will work for you:

{{ site.time | date: '%y' }}

How do I show a Jekyll Collection item on a specific date? (Liquid syntax issue?)

This is happening because the front matter is YAML, and YAML might be more clever than you thought it would.

date: 2020-06-17

Is an actual valid date for YAML.

So if I JSON print such a date defined in a front matter, then, it would show as a date:

{{ quip.date | json }}

2020-06-17 00:00:00 +0200

So if you want to compare dates from the front matter and from the day, you'll have to format both dates.

{% assign now = "now" | date: "%Y-%m-%d" %}
{% assign show = quip.show | date: "%Y-%m-%d" %}
{% if show == now %}
<p class="fresh-from-the-day">quip.title</p>
{% endif %}

Ordinalize date formatting in Liquid/Jekyll (e.g. 1st, 3rd and 4th)

The Liquid Template Engine that Jekyll uses doesn't offer the ability to ordinalize (e.g. turn "1" into "1st" and "3" into "3rd") out of the box. However, it is possible to use filters and tags to provide that functionality. The snippet below produces the day of month number with an ordanilized string appended. It also removes the leading zero for the first nine days of the month.

{% assign d = page.date | date: "%-d" %}
{% case d %}
{% when "1" or "21" or "31" %}{{ d }}st
{% when "2" or "22" %}{{ d }}nd
{% when "3" or "23" %}{{ d }}rd
{% else %}{{ d }}th
{% endcase %}

For a full date with month, day and year, use this:

{% assign d = page.date | date: "%-d" %}
{{ page.date | date: "%B" }}
{% case d %}{% when "1" or "21" or "31" %}{{ d }}st{% when "2" or "22" %}{{ d }}nd{% when "3" or "23" %}{{ d }}rd{% else %}{{ d }}th{% endcase %},
{{ page.date | date: "%Y" }}

which produces output like:

September 21st, 2013

Note: The code is split onto multiple lines to make it easier to read. It will render fine in HTML but will have extra whitespace in the source code. If that bothers you, simply move everything to one line.

If you are interested in other date formatting options, I create this reference: Jekyll (and GitHub Pages) Liquid Date Formatting Examples

How do I show current age using liquid?

You can either use JS with libraries like moment to compute the birthday client-side, like this: