How do I display the current year?

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

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

3 Likes

Getting year for a post date variable you can do:

{{ .Date.Format "2006" }}
2 Likes

Current year for footer:

{{ .Now.Format "2006" }}

1 Like

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.

Display the current year using the template function dateFormat:

{{ dateFormat "2006" now }}

1 Like

Also work {{ now.Year }}

4 Likes

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

1 Like

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

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.

Why “2006”?

It’s just a strange syntax for specifying date format… think 1, 2, 3, 4, 5, 6, 7:

Number Meaning Examples
1 month 01, Jan, January
2 day 02, Mon, Monday
3 hour 03, 15
4 minute 04
5 seconds 05
6 year 06, 2006
7 timezone -0700, -07:00, -07, MST

References:


Update: Just blogged about this – Time formatting in Go

4 Likes

Update 2022:

It’s

{{ now.Year }}

Source: now | Hugo

4 Likes