Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Formatting date in DB2

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

New User


Joined: 17 Jun 2009
Posts: 35
Location: Denver

PostPosted: Thu Dec 03, 2015 3:18 am    Post subject: Formatting date in DB2
Reply with quote

Hi

I have a column in a DB2 table which is of DATE datatype.
The value stored is 2015-12-02.
I need to write a SELECT query which I can run using IKJEFT01 which will format it as '20151202'

I used

SELECT CHAR(YEAR(ONLINE_DATE))||
CHAR(MONTH(ONLINE_DATE))||
CHAR(DAY(ONLINE_DATE)).

But it returned me

2015 12 2

Is there anyway to achieve this. I tried using SUBSTR. But it was throwing some error. Can we use SUBSTR on a DATE column

Any advice is appreciated
Back to top
View user's profile Send private message

manugeorge2004

New User


Joined: 17 Jun 2009
Posts: 35
Location: Denver

PostPosted: Thu Dec 03, 2015 3:23 am    Post subject:
Reply with quote

Please ignore this. Below worked

SELECT SUBSTR(CHAR(ONLINE_DATE),1,4),
SUBSTR(CHAR(ONLINE_DATE),6,2),
SUBSTR(CHAR(ONLINE_DATE),9,2)
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


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

PostPosted: Thu Dec 03, 2015 3:35 am    Post subject:
Reply with quote

Easy,
Code:
select replace('2015-12-02','-','') from sysibm.sysdummy1
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Thu Dec 03, 2015 5:32 pm    Post subject:
Reply with quote

Quote:
But it was throwing some error.

No it didn't. Why? Because nothing on the mainframe "throws" an error. You could have said that it errored in the same manner - but it was not an error, just the wrong output.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Thu Dec 03, 2015 7:17 pm    Post subject: Reply to: Formatting date in DB2
Reply with quote

You could also use:
Code:
SELECT VARCHAR_FORMAT(my_date,'YYYYMMDD')
FROM my.table
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 TOT & DATE parameter in ICEMAN hemanthj642 DFSORT/ICETOOL 4 Mon Nov 14, 2016 5:19 am
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
This topic is locked: you cannot edit posts or make replies. Get correct date and time when curren... balaji81_k DB2 24 Fri Oct 14, 2016 10:40 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts Add system date inside of a PS file a... pramitdas DFSORT/ICETOOL 5 Sun Aug 28, 2016 12:06 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us