Format date to string

你离开我真会死。 提交于 2019-12-09 13:29:50

问题


I'm trying to format a db2 date into a string as "YYYY/MM/DD".

The best I got so far is:

SELECT CAST(YEAR(MYDATE) AS VARCHAR(4)) || '/'
|| CAST(MONTH(MYDATE) AS VARCHAR(2))    || '/'
|| RIGHT('00' || CAST(DAY(MYDATE) AS VARCHAR(2)), 2) FROM MYCALENDAR

Is there a better, terser way to do this?

ps: Toying around with locales is not an option.


回答1:


According to the IBM documentation the following should work:

 SELECT VARCHAR_FORMAT(MYDATE, 'YYYY/MM/DD') FROM MYCALENDAR;


来源:https://stackoverflow.com/questions/9083121/format-date-to-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!