Get today's date in Jekyll with Liquid markup

RubyDatetimeJekyllLiquid

Ruby Problem Overview


This (should) be easy, I think, but I'm unable to get today's date to show in a Jekyll page using Liquid markup. According to the documentation, I should be able to do this to get this date's year:

{{ 'now' | date: "%Y" }}

But all that gets rendered is the string now, not any formatted date. What am I doing wrong?

Ruby Solutions


Solution 1 - Ruby

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' }}

Solution 2 - Ruby

To get the whole year, for example "2015", from the site.time, you can either use:

{{ site.time | date: '%Y' }}
# OR
20{{ site.time | date: '%y' }}

To just get the last 2 digits from the year 2015, this will just output "15":

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

Solution 3 - Ruby

Perhaps the question title is misleading but I actually wanted today's date and not the year. This works for me:

{{ site.time | date: '%B %d, %Y' }}

Today it produced: January 04, 2019

Solution 4 - Ruby

{{ site.time }} represent the time the site did get updated it is a fixed date not a dynamic one.

Such request require Javascript with Date.getTime() or Date.now() example:

<script>document.write(Math.round(Date.now() / (365 * 24 * 60 * 60 * 1000) + 1970 - 1));</script>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeff PrattView Question on Stackoverflow
Solution 1 - RubyMark ThomasView Answer on Stackoverflow
Solution 2 - Ruby5ervant - techintel.github.ioView Answer on Stackoverflow
Solution 3 - RubyMobileMateoView Answer on Stackoverflow
Solution 4 - RubyintikaView Answer on Stackoverflow