Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Created February 1, 2022 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviddarnes/deffd14f8f32f8106fcf7562d0c5a2bd to your computer and use it in GitHub Desktop.
Save daviddarnes/deffd14f8f32f8106fcf7562d0c5a2bd to your computer and use it in GitHub Desktop.
Calculate the last day of the month using liquid only
{%- capture current_month %}{{ site.time | date: '%m' }}{% endcapture -%}
{%- capture future_date %}{{ site.time | date: '%Y' }}-{% if current_month == 12 %}01{% else %}{{ current_month | plus: 1 }}{% endif %}-01{% endcapture -%}
{%- capture epoc_end_month_date %}{{ future_date | date: '%s' }}{% endcapture -%}
{{ epoc_end_month_date | minus: 86400 | date: "%B" }}{{ " " }}
{%- assign day = epoc_end_month_date | minus: 86400 | date: "%-d" -%}
{%- case day -%}
{%- when '1' or '21' or '31' -%}{{ day }}st
{%- when '2' or '22' -%}{{ day }}nd
{%- when '3' or '23' -%}{{ day }}rd
{%- else %}{{ day }}th
{%- endcase -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment