網頁

2013年8月29日 星期四

DB2: Get current date with format YYYYMMDD

How to get current date with format YYYYMMSS in DB2??

To get the current date, time, and timestamp using SQL in DB2, reference to use below sql statment
db2 => select current date from sysibm.sysdummy1 1 ---------- 08/29/2013 1 record(s) selected. db2 => select current time from sysibm.sysdummy1 1 -------- 16:59:01 1 record(s) selected. db2 => select current timestamp from sysibm.sysdummy1 1 -------------------------- 2013-08-29-16.37.35.960388 1 record(s) selected.

How to custom date/time formatting?
The easy way to do this is use VARCHAR_FORMATscalar function
db2 => select varchar_format(current timestamp, 'YYYYMMDD') from sysibm.sysdummy1 1 ----------------------------------- 20130829 1 record(s) selected.

沒有留言:

張貼留言