How to compare post's date year to current year

I would like to hide the year part of the date if the post was created in the current year, otherwise, show the year. So I was trying to compare the post’s date year with the current date year.

{{ if eq .Date.Year now.Year }}
    {{ .Date.Format "January 2" }}
{{ else }}
    {{ .Date.Format "January 2, 2016" }}
{{ end }}

I expected to see “January 2” for the posts created this year and “January 2, 2016” for the posts created previous to this year.

But instead, I am seeing “January 2, 2016” formatting for all posts. Where 2016 is parsed from “ddmm6”. Like “September 8, 8096” and “August 29, 29086”.

1 Like

2016 is an invalid date format. What you want is 2006

For reference see

1 Like

:man_facepalming: of course
I didn’t think that it required literally the exact same date and time to parse correctly. Thank you for pointing it out.

Yeah the date formatting can feel peculiar at first