DB2 Date format

后端 未结 5 1744
粉色の甜心
粉色の甜心 2020-12-31 03:08

I just want to format current date into yyyymmdd in DB2.

I see the date formats available, but how can I use them?

http://publib.boulder.ibm.com

相关标签:
5条回答
  • 2020-12-31 03:34

    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
    
    0 讨论(0)
  • 2020-12-31 03:41

    Current date is in yyyy-mm-dd format. You can convert it into yyyymmdd format using substring function:

    select substr(current date,1,4)||substr(current date,6,2)||substr(currentdate,9,2)
    
    0 讨论(0)
  • 2020-12-31 03:43

    One more solution REPLACE (CHAR(current date, ISO),'-','')

    0 讨论(0)
  • 2020-12-31 03:48
    select to_char(current date, 'yyyymmdd') from sysibm.sysdummy1
    

    result: 20160510

    0 讨论(0)
  • 2020-12-31 03:56
    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().

    0 讨论(0)
提交回复
热议问题