DAYOFYEAR scalar function

The DAYOFYEAR function returns an integer, in the range 1–366 that represents the day of the year, where 1 is January 1.

Read syntax diagramSkip visual syntax diagramDAYOFYEAR( expression)

The schema is SYSIBM.

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

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 that is 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 timestamp with a time zone value, 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.

Examples for DAYOFYEAR

Example 1
Using sample table DSN8C10.EMP, set the integer host variable AVG_DAY_OF_YEAR to the average of the day of the year on which employees were hired (HIREDATE). The result is that AVG_DAY_OF_YEAR is set to 202.
   SELECT AVG(DAYOFYEAR(HIREDATE))
     INTO :AVG_DAY_OF_YEAR
     FROM DSN8C10.EMP;
Example 2

The following invocations of the DAYOFYEAR function all return the same result, which is 2. When the input argument contains a time zone, the result is determined from the UTC representation of the input value. The string representations of timestamps with a time zone in the example SELECT statement all have the same UTC representation: 2003-01-02-20.00.00.

SELECT DAYOFYEAR('2003-01-02-20.00.00'), 
			DAYOFYEAR('2003-01-02-12.00.00-08:00'), 
			DAYOFYEAR('2003-01-03-05.00.00+09:00') 
		FROM SYSIBM.SYSDUMMY1;