How do I display the current year?


#1

Trying to put the current year in the footer of my theme. Is there a way i can dynamically add that?


#2

Ok I figured it out it’s {{ .Now.Year }}


#3

Getting year for a post date variable you can do:

{{ .Date.Format "2006" }}

#4

Current year for footer:

{{ .Now.Format "2006" }}


#5

I’ve been using .Now.Year but told it is deprecated and to use the now template function. How do you use it? Its not documented and can’t seem to find a forum post about using it. Not on http://gohugo.io/templates/functions/ or the netlify version of site.

The reason I ask is because I can’t .Now.Year in my custom RSS but can do it in a partial.


#6

Display the current year using the template function dateFormat:

{{ dateFormat "2006" now }}


#7

Also work {{ now.Year }}


#8

{{ now.Format “2006” }} is what ultimately worked for me.


#9

I’ve got the latest version of Hugo (0.29) and I can’t get the year to work.


#10

Both of the below work for me on version 0.30-DEV.

{{ now.Format "2006" }}

and

{{ dateFormat "2006" now }}

It might help if you can upload your example site somewhere (github, gitlab) and paste a link to that.