Smart Timestamp formatting


#1

Does anyone know how to format timestamps based on today’s date? For posts published within the current calendar year, I want to exclude the year from being displayed. But for posts published before the current year, I want to include the year (illustrated below).

e.g. Saturday, Jan 2 10:15pm / Friday, December 31, 2016 7:05pm


#2

How about something like:

{% assign now_year = "now" | date: "%Y" %}
{% assign post_year = page.date | date: "%Y" %}
{% if now_year == post_year %}
  {% assign post_date = page.date | date: "%A, %b %e %I:%M%P" %}
{% else %}
  {% assign post_date = page.date | date: "%A, %b %e, %Y %I:%M%P" %}
{% endif %}

Use {{ post_date }} in your template.