IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how can I format DATE field use SQL


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
liying

New User


Joined: 27 May 2010
Posts: 47
Location: da lian.china

PostPosted: Thu Jan 07, 2016 2:20 pm
Reply with quote

I want to format DATE field use sql

data in table:

Object_date
2015/01/01
2015/01/02
2015/01/03

Result I want by SQL SELECT:

Result_date
2015-01-01
2015-01-02
2015-01-03

Both the attribute is CHAR(10). Is there any way without use complicate function like YEAR(Object_date) ||'-'||Month(Object_date)||'-'||Day(Object_date)?
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Jan 07, 2016 7:57 pm
Reply with quote

I have already recommended the use of the VARCHAR_FORMAT function,
however I read somewhere that in some versions of SQL it works only with TIMESTAMP, not DATE.
You'll have to try and tell us.
Back to top
View user's profile Send private message
liying

New User


Joined: 27 May 2010
Posts: 47
Location: da lian.china

PostPosted: Fri Jan 08, 2016 6:48 am
Reply with quote

Marso wrote:
I have already recommended the use of the VARCHAR_FORMAT function,
however I read somewhere that in some versions of SQL it works only with TIMESTAMP, not DATE.
You'll have to try and tell us.


Thank you for your reply.

VARCHAR_FORMAT do not work with DATE type filed format. I have find the way like this .

SELECT REPLACE(START_DATE,'/','-') FROM tabl1
FETCH FIRST 100 ROWS ONLY

And my problem have been solved. Thank again for your attention.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Sun Jan 10, 2016 12:38 am
Reply with quote

solution to this have been already discussed multiple times on this forum before even you post such questions should have checked to reduce the duplicates.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
Search our Forums:

Back to Top