Avatar of Camillia
Camillia
Flag for United States of America asked on

Formatting date to mm/dd/yyyy

I read the date field in AS400 database, and it looks like this:
2007-01-12

anyway i can display it/ format it as mm/dd/yyyy with a command? or do I need to parse it and put it back together?
in sql server, i use convert(varchar(12),mydate,101)
DB2

Avatar of undefined
Last Comment
Camillia

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

you should be able to use TO_CHAR(yourfield, 'MM/DD/YYYY')
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Camillia

ASKER
TO_CHAR is not recognized. Let me go thru that link and see...
Camillia

ASKER
Tried VARCHAR_FORMAT as well, didnt work...
 select  To_CHAR(chadat,'MM/DD/YYYY')..

gives me the error : TO_CHAR in *LIBL type *N not found..

the field in the database is "Date"..is it because of the version of iSeries/As400??
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Camillia

ASKER
That article is for DB2 windows/Linux. so that wont work for me..

I tried
Select
         Char( Date('1978-01-27', USA ) )
From
         Sysibm.Sysdummy1

but got the error :USA is not defined in table..

any ideas?
Camillia

ASKER
found my answer

Select
Char(Date('1978-01-27'),USA )
From
Sysibm.Sysdummy1
Member_2_2484401


This works for me on DB2 for iSeries (AS/400) v5r3

select char(effectiveDate, USA)
from    coverageperiod

I think you forgot a parenthesis in your query. (right after the date)

HTH,
DaveSlash
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Camillia

ASKER
yeah, thanks..

anway to have it as  dd/mm/yyyy as well??
Member_2_2484401


This gets you close ...

Select
         Char( effectiveDate, EUR )
From
         coverageperiod            

You might also try:

Select
         Char( effectiveDate, LOCAL )
From
         coverageperiod

HTH,
DaveSlash
Camillia

ASKER
Thanks Dave.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes