YEAR(date) returns the calendar year as an integer: 1 January 2021 is 2021. It is the same as DATEPART('year', date). In DuckDB the match is year(). Don't reach for isoyear(): the ISO year moves the first days of January into the previous year.
Updated · Checked on the xmetric engine
What is the syntax?
YEAR(date)
date
a date or date-time.
Returns an integer: the calendar year of date. Null if the date is null.
What does it return, and what is the SQL?
Each example runs on the same 9 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
Which year was each order placed in?
Tableau
YEAR([Ordered])
SQL (DuckDB)
SELECTyear(Ordered) AS result
FROM input
ORDERBY id
Orders 1 and 2 are in the first days of 2021, so they return 2021 even though their ISO week belongs to 2020.
Ordered
Result
2021-01-0108:00
2,021
2021-01-0318:45
2,021
2024-02-2910:15
2,024
2024-12-2916:25:40
2,024
2024-12-3009:05
2,024
2025-01-3123:59:59
2,025
2025-03-0100:00
2,025
2025-03-0212:30:15
2,025
null
✓ The Tableau formula and the SQL return the same 9 rows.
Which fiscal year starting in July does each order fall in?
Tableau
YEAR(DATEADD('month', 6, [Ordered]))
SQL (DuckDB)
SELECTyear(Ordered +INTERVAL6 MONTH) AS result
FROM input
ORDERBY id
Shift the date forward six months, then take the year: March 2025 is fiscal 2025, December 2024 is fiscal 2025 too.
Ordered
Result
2021-01-0108:00
2,021
2021-01-0318:45
2,021
2024-02-2910:15
2,024
2024-12-2916:25:40
2,025
2024-12-3009:05
2,025
2025-01-3123:59:59
2,025
2025-03-0100:00
2,025
2025-03-0212:30:15
2,025
null
✓ The Tableau formula and the SQL return the same 9 rows.
Where does a straight translation go wrong?
Common mistake
Why does isoyear() put 1 January 2021 in 2020?
The ISO year follows ISO weeks, and 1 January 2021 is a Friday in ISO week 53 of 2020. YEAR is the plain calendar year, so orders 1 and 2 are 2021 in Tableau and 2020 with isoyear().
Tableau
YEAR([Ordered])
Tempting SQL
SELECTisoyear(Ordered) AS result
FROM input
ORDERBY id
SQL that matches
SELECTyear(Ordered) AS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
2,021
2,020
2,021
2021-01-0318:45
2,021
2,020
2,021
2024-02-2910:15
2,024
2,024
2,024
2024-12-2916:25:40
2,024
2,024
2,024
2024-12-3009:05
2,024
2,025
2,024
2025-01-3123:59:59
2,025
2,025
2,025
2025-03-0100:00
2,025
2,025
2,025
2025-03-0212:30:15
2,025
2,025
2,025
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
How do I write it in Snowflake or BigQuery?
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.
Snowflake
SELECTYEAR(Ordered) AS result
FROM input
ORDERBY id
Yes. Both return an integer. DATENAME('year', ...) returns the same digits as a string.
What does YEAR return for a null date?
Null. The last sample row has no order date, and YEAR returns null there, as does year() in SQL.
Why does Tableau show 2,021 instead of 2021?
YEAR returns a number, and the default number format adds a thousands separator. Format the field as a number with no separator, or use DATENAME('year', ...) for a string.