Dateformat

create your own dateformat function

simply declare your own function like this:

create function date_fmt(TS date, fmt varchar(30))
returns varchar(50)
return
with tmp (dd,mm,yyyy) as
(
select
substr( digits (day(TS)),9),
substr( digits (month(TS)),9) ,
rtrim(char(year(TS))) ,
from sysibm.sysdummy1
)
select
case fmt
when 'yyyymmdd'
then yyyy || mm || dd
when 'mm/dd/yyyy'
then mm || '/' || dd || '/' || yyyy
when '222'
then dd || '.' || mm || '.' || yyyy
else
'date format ' || coalesce(fmt,' ') ||
' not recognized.'
end
from tmp

Taggings:

Date format in IBM DB2 Databases ?

Sometimes there is a need for a DATE-format for a field in IBM DB2 Databases... well Its not that easy like when using Oracle DBs, so what will we have to do to archieve a usable dateformat ? Well isnĀ“t there an easy prepared function we could use ? NO. so what ?
Subscribe to Dateformat