DAYS_TO_END_OF_MONTH scalar function

The DAYS_TO_END_OF_MONTH function returns the number of days to the end of the month.

Read syntax diagramSkip visual syntax diagramDAYS_TO_END_OF_MONTH(expression )

The schema is SYSIBM.

expression
An expression that specifies the datetime value for which the number of days to the end of the month is computed. The expression must return a value that is a DATE, TIMESTAMP, CHAR, or VARCHAR data type. In a Unicode database, the expression can also be a GRAPHIC or VARGRAPHIC data type. CHAR, VARCHAR, GRAPHIC, and VARGRAPHIC are supported by using implicit casting. If expression is a CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type, it must be a valid string that is accepted by the TIMESTAMP scalar function.

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

Examples

  1. Set the host variable NUMDAYS as the number of days to the end of the month for the date February 20, 2012.
       SET :NUMDAYS = DAYS_TO_END_OF_MONTH(DATE '2012-02-20')
    The host variable NUMDAYS is set with the value 9.
  2. The DAYS_TO_END_OF_MONTH function and datetime arithmetic with DAYS and LAST_DAY functions can be used to achieve the same results. The following examples demonstrate this.
       SET :NUMDAYS = DAYS(LAST_DAY(date '2013-02-20')) - DAYS(date '2013-02-20')
       SET :NUMDAYS = DAYS_TO_END_OF_MONTH(DATE '2013-02-20')
    In both cases, the host variable NUMDAYS is set with the value 8.