YEAR scalar function

The YEAR function returns the year part of a value that is a character or graphic string. The value must be a valid string representation of a date or timestamp.

Read syntax diagramSkip visual syntax diagramYEAR( expression)

The schema is SYSIBM.

The argument must be an expression that returns one of the following built-in data types: a date, a timestamp, a character string, a graphic string, or a numeric data type.

  • If expression is a character or graphic string, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a date or timestamp with an actual length of not greater than 255 bytes. For the valid formats of string representations of dates and timestamps, see String representations of datetime values.
  • If expression is a number, it must be a date or timestamp duration. For the valid formats of date and timestamp durations, see Datetime operands.

If expression is a timestamp with a time zone, or a valid string representation of a timestamp with a time zone, the result is determined from the UTC representation of the datetime value.

The result of the function is a large integer.

The result can be null; if the argument is null, the result is the null value.

The other rules depend on the data type of the argument specified:

  • If the argument is a date, a timestamp, or a string representation of either, the result is the year part of the value, which is an integer in the range 1–9999.
  • If the argument is a date duration or a timestamp duration, the result is the year part of the value, which is an integer between -9999 and 9999. A nonzero result has the same sign as the argument.
  • If the argument contains a time zone, the result is the year part of the value expressed in UTC.
Example 1: From the table DSN8C10.EMP, select all rows for employees who were born in 1941.
   SELECT *
     FROM DSN8C10.EMP
     WHERE YEAR(BIRTHDATE) = 1941;
Example 2: The following invocations of the YEAR function returns the same result:
SELECT YEAR('1993-08-10-20.00.00'), 
			YEAR('1993-08-10-20.00.00-08:00'), 
			YEAR('1993-08-10-20.00.00+09:00') 
		FROM SYSIBM.SYSDUMMY1;
For each invocation of the YEAR function in this SELECT statement, the result is 1993.

When the input argument contains a time zone, the result is determined from the UTC representation of the input value. The string representations of a timestamp with a time zone in the SELECT statement all have the same UTC representation: '1993-08-10-20.00.00'.