WEEK scalar function

The WEEK function returns an integer in the range of 1 to 54 that represents the week of the year. The week starts with Sunday, and January 1 is always in the first week.

Read syntax diagramSkip visual syntax diagramWEEK( 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, 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.

Example 1: Using sample table DSN8C10.PROJ, set the integer host variable WEEK to the week of the year that project 'AD2100' ended.
   SELECT WEEK(PRENDATE)
     INTO :WEEK
     FROM DSN8C10.PROJ
     WHERE PROJNO = 'AD2100';
The result is that WEEK is set 6.
Example 2: The following invocations of the WEEK function returns the same result:
SELECT WEEK('1993-08-10-20.00.00'), 
			WEEK('1993-08-10-20.00.00-08:00'), 
			WEEK('1993-08-10-20.00.00+09:00') 
		FROM SYSIBM.SYSDUMMY1;
For each invocation of the WEEK function in this SELECT statement, the result is 33.

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'.