I just want to format current date into yyyymmdd
in DB2.
I see the date formats available, but how can I use them?
SELECT CURDATE() FROM SYSIBM.SYSDUMMY1;
I dont see any straightforward way to use the above listed formats.
Any suggestion?
I just want to format current date into yyyymmdd
in DB2.
I see the date formats available, but how can I use them?
SELECT CURDATE() FROM SYSIBM.SYSDUMMY1;
I dont see any straightforward way to use the above listed formats.
Any suggestion?
SELECT VARCHAR_FORMAT(CURRENT TIMESTAMP, 'YYYYMMDD')
FROM SYSIBM.SYSDUMMY1
Should work on both Mainframe and Linux/Unix/Windows DB2. Info Center entry for VARCHAR_FORMAT()
.
select to_char(current date, 'yyyymmdd') from sysibm.sysdummy1
result: 20160510
This isn't straightforward, but
SELECT CHAR(CURRENT DATE, ISO) FROM SYSIBM.SYSDUMMY1
returns the current date in yyyy-mm-dd format. You would have to substring and concatenate the result to get yyyymmdd.
SELECT SUBSTR(CHAR(CURRENT DATE, ISO), 1, 4) ||
SUBSTR(CHAR(CURRENT DATE, ISO), 6, 2) ||
SUBSTR(CHAR(CURRENT DATE, ISO), 9, 2)
FROM SYSIBM.SYSDUMMY1