Sarathlal N

Date formats in Liquid Templating Engine & Jekyll

The Date is an essential entity for blogs. The blogs are contents arranged in reverse chronological order. If we don’t have a published date, there is no blogging at all.

My blog is a Jekyll powered static website and it use Liquid Templating Engine. I like to use dates in different formats at here. After some readings, I collected a list of date formats usable in Liquid for Jekyll & GitHub pages.

The simple Liquid date tag {{ }} can generate published date like 2014-01-15 00:00:00 +0530. Are you like this published date for our Jekyll blog post?

Now we can try to change our date format to display more concise one. The {{ | date_to_string }} can generate a neat date like 26 Jan 2014.

There are some default built-in Liquid date formats to get date in Jekyll pages. Why can’t try them?

The {{ | date: "%c" }} can output date like Sun Jan 26 00:00:00 2014 and the {{ | date: "%x" }} result will be 01/26/14.

Are you irritated with these examples? I realize that they are enough for certain situations. But if you need more flexibility, we can add some filters and generate new date formats.

Can you try {{ | date: "%B %d, %Y" }}? This will generate date like January 26, 2014.

Even if you need the name of the day with your dates like Sunday - Jan 26, 2014, insert {{ | date: "%A - %b %d, %Y" }}.

What is your opinion about 26-01-2014 and 26/01/2014. The {{ | date: "%d-%m-%Y" }} and {{ | date: "%d/%m/%Y" }} can generate them.

The beginning 0 on date and month annoying me. Have you tried {{ | date: "%B %-d, %Y"}} or {{ | date: "%-d/%-m/%y"}}. The result will be omitting 0 from the beginning like January 26, 2014 and 26/1/14.

Even if you like to use last two digit of year with your date like 1/26/14, date tag {{ | date: "%-m/%-d/%y"}} can solve your problem.

Have you get your favorite date format for your Jekyll blog that use Liquid Template engine? Else combine and replace some elements and try yourself.

Recent Posts

  1. Action hooks that trigger on, before or after add, update or delete actions of option - WordPress
  2. Get all variations of a variable product - WooCommerce
  3. Generate random string - Python
  4. Split domain from an email address - Python
  5. Get upcoming N days - PHP

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.