SQL LAST_DAY scalar function in DB2 for i SQL |
LAST_DAY
The LAST_DAY scalar function returns the date which is the last day of the month of the passed date/timestamp/valid string represent date or timestamp.
Syntax
LAST_DAY(expression)
Example 1: Passing date as string.
SELECT LAST_DAY('2024-03-23') FROM SYSIBM.SYSDUMMY1
Output:
LAST_DAY 03/31/24
Example 2: Passing timestamp as string.
SELECT LAST_DAY('2024-03-23-09.44.52.982603') FROM SYSIBM.SYSDUMMY1
Output:
LAST_DAY 03/31/24
Example 3: Passing date.
SELECT LAST_DAY(current date) FROM SYSIBM.SYSDUMMY1
Or
SELECT LAST_DAY(current_date) FROM SYSIBM.SYSDUMMY1
Output:
LAST_DAY 03/31/24
Example 4: Passing timestamp.
SELECT LAST_DAY(current timestamp) FROM SYSIBM.SYSDUMMY1
Or
SELECT LAST_DAY(current_timestamp) FROM SYSIBM.SYSDUMMY1
Output:
LAST_DAY 2024-03-31-09.46.46.997718