DAYS scalar function
The DAYS function returns an integer representation of a date.
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.
The result is 1 more than the number of days from January 1, 0001 to D, where D is the date that would occur if the DATE function were applied to the argument.
Examples for DAYS
- Example 1
- Set the INTEGER host variable DAYSVAR to the number of days that employee 140 had been with the company on the last day of 1997.
EXEC SQL SELECT DAYS('1997-12-31') - DAYS(HIREDATE) + 1 INTO :DAYSVAR FROM DSN8C10.EMP WHERE EMPNO = '000140';
- Example 2
- The following invocations of the DAYS function all return the same result, which is 731217. 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 DAYS('2003-01-02-20.00.00'), DAYS('2003-01-02-12.00.00-08:00'), DAYS('2003-01-03-05.00.00+09:00') FROM SYSIBM.SYSDUMMY1;