Hitachi

Hitachi Advanced Database SQL Reference


8.9.6 LASTDAY

Returns the date or datetime of the last day of the month specified in the datetime data.

Organization of this subsection

(1) Specification format

scalar-function-LASTDAY ::= {LASTDAY|LAST_DAY}(datetime-data)
 
  datetime-data ::= value-expression

(2) Explanation of specification format

datetime-data:

Specifies the datetime data to be processed.

The following rules apply:

  • Specify datetime-data in the form of a value expression. For details about value expressions, see 7.20 Value expression.

  • The data type of datetime-data must be DATE, TIMESTAMP, CHAR, or VARCHAR. In the case of CHAR or VARCHAR, you must specify a character string literal that adheres to the format of the predefined input representation of a date or time stamp. For details about predefined input representations, see 6.3.3 Predefined character-string representations.

  • You cannot specify a dynamic parameter by itself for datetime-data.

(3) Rules

  1. The data type of the execution result will be as follows.

    • If datetime-data is a DATE type or a predefined input representation of a date (CHAR or VARCHAR type), the data type of the execution result will be DATE.

    • If datetime-data is a TIMESTAMP type or a predefined input representation of a time stamp (CHAR or VARCHAR type), the data type of the execution result will be TIMESTAMP.

  2. The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).

  3. If datetime-data is the null value, the execution result will be the null value.

  4. If datetime-data is a TIMESTAMP type or a predefined input representation of a time stamp (CHAR or VARCHAR type), the values that were entered for the hours, minutes, seconds, and fractional seconds parts are returned unchanged.

    Example

    LASTDAY(TIMESTAMP'2014-07-03 15:30:45.123')'2014-07-31 15:30:45.123'

(4) Example

Example:

Determine the date of the last day of the month of the datetime data in column C2 of table T1.

SELECT "C1",LASTDAY("C2") FROM "T1"

[Figure]