Search code examples
postgresqlkettledata-integration

How to convert '02-3月 -21' to date 21-03-02 00:00:00 psql


How to convert '02-3月 -21' to date 21-03-02 00:00:00? in postgresql or kettle


Solution

  • I think a simple replace can do the trick here. Just replace the Chinese character with nothing and format it.

    SELECT TO_TIMESTAMP(REPLACE ('02-3月-21', '月', ''),'DD-MM-YY');
    // output: 2021-03-02 00:00:00+00
    
    
    SELECT TO_CHAR(TO_TIMESTAMP(REPLACE ('02-3月-21', '月', ''),'DD-MM-YY'), 'YY-MM-DD HH24:MI:SS')
    // output: 21-03-02 00:00:00