Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
how can I format DATE field use SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
liying

New User


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

PostPosted: Thu Jan 07, 2016 2:20 pm    Post subject: how can I format DATE field use SQL
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: 1252
Location: Israel

PostPosted: Thu Jan 07, 2016 7:57 pm    Post subject:
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: 43
Location: da lian.china

PostPosted: Fri Jan 08, 2016 6:48 am    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1827
Location: NY,USA

PostPosted: Sun Jan 10, 2016 12:38 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fetching data from JHS as per the cur... arunsoods All Other Mainframe Topics 4 Wed Nov 22, 2017 1:54 pm
No new posts Date in where clause - Windows Karthikeyan Subbarayan DB2 9 Wed Nov 15, 2017 9:07 pm
This topic is locked: you cannot edit posts or make replies. Incrementing current time field by 30... arunsoods DFSORT/ICETOOL 11 Thu Oct 26, 2017 3:22 pm
No new posts Format Last Record differently from r... Learncoholic DFSORT/ICETOOL 5 Tue Oct 24, 2017 12:01 pm
No new posts Format issues using XMITIP MSGDD ssdjp1 CLIST & REXX 5 Mon Oct 23, 2017 8:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us