DAYOFWEEK

The DAYOFWEEK function returns an integer between 1 and 7 that represents the day of the week, where 1 is Sunday and 7 is Saturday.

Read syntax diagramSkip visual syntax diagramDAYOFWEEK (expression)

For another alternative, see DAYOFWEEK_ISO.

expression
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, its value must be a valid string representation of a date or timestamp. For the valid formats of string representations of dates and timestamps, see String representations of datetime values.

The result of the function is a large integer. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Example

  • Using the EMPLOYEE table, set the host variable DAY_OF_WEEK (INTEGER) to the day of the week that Christine Haas (EMPNO=‘000010') started (HIREDATE).
      SELECT DAYOFWEEK(HIREDATE)
        INTO :DAY_OF_WEEK
        FROM EMPLOYEE     
        WHERE EMPNO = '000010'
    Results in DAY_OF_WEEK being set to 6, which represents Friday.
  • The following query returns four values: 1, 2, 1, and 2.
      SELECT DAYOFWEEK(CAST('10/11/1998' AS DATE)),
             DAYOFWEEK(TIMESTAMP('10/12/1998','01.02')),
             DAYOFWEEK(CAST(CAST('10/11/1998' AS DATE) AS CHAR(20))),
             DAYOFWEEK(CAST(TIMESTAMP('10/12/1998','01.02') AS CHAR(26)))
         FROM SYSIBM.SYSDUMMY1