YEAR
Description
The YEAR function is used to extract the year part from different types of date expressions and return it as an integer.
Syntax
Parameter Description
expr
: Can be different types of date expressions, including strings (date/string), time (time/timez), and timestamps (timestamp/timestamptz).
Return Type
Integer (int)
Usage Example
- Extract the year from a date in string form:
- Extract the year from the current timestamp:
Notes
- When the input date expression is of string type, please ensure it conforms to the date format supported by the database, otherwise it may cause parsing errors.
- When the input time expression only contains the time part, the YEAR function will return 0000 as the year.
- When using the YEAR function, please ensure the parameter type is correct to avoid type mismatch errors.