Reputation: 1
Hi everyone I have a date data like this 23/01/22 (dd/mm/yy), I want to extract the year with EXTRACT(YEAR from date) it returns the value of 2023 instead of 2022. Does anyone know how to solve this?
Upvotes: 0
Views: 37
Reputation: 9038
Always use proper date datatype.
Workaround:
select EXTRACT(YEAR from str_to_date('23/01/22','%d/%m/%y')) ;
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=ef455c01586b5b0cee2d13b49dc2cc56
Upvotes: 2