DAY scalar function
The DAY function returns the day part of a value.
The schema is SYSIBM.
-
expression
- An expression that returns a value of one of the following built-in
data types: DATE, TIMESTAMP, numeric, or character string that is
not a CLOB.
If the value is a number, it must be a date duration or timestamp duration (SQLSTATE 42815).
If the value is a character string, it must be a valid string representation of a date or timestamp. In a Unicode database, if the value is a graphic string (except DBCLOB), it is first converted to a character string before the function is executed.
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.
The other rules depend on the data type of the argument:
- If the argument is a DATE, TIMESTAMP, or valid string representation
of a date or timestamp:
- The result is the day part of the value, which is an integer between 1 and 31.
- If the argument is a date duration or timestamp duration:
- The result is the day part of the value, which is an integer between -99 and 99. A nonzero result has the same sign as the argument.
Examples
- Example 1: Using the PROJECT table, set the host variable
END_DAY (smallint) to the day that the WELD LINE PLANNING project
(PROJNAME) is scheduled to stop (PRENDATE).
Results in END_DAY being set to 15 when using the sample table.SELECT DAY(PRENDATE) INTO :END_DAY FROM PROJECT WHERE PROJNAME = 'WELD LINE PLANNING'
- Example 2: Assume that the column DATE1 (whose data type
is DATE) has an internal value equivalent to 2000-03-15 and the column
DATE2 (whose data type is DATE) has an internal value equivalent to
1999-12-31.
Results in the value 15.DAY(DATE1 - DATE2)