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
 
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: 1785
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: 1868
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: 1243
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 Validate the Date girishb2 DFSORT/ICETOOL 9 Tue Sep 19, 2017 1:12 am
No new posts Julian Date to CICS ABSTTIME blayek CICS 3 Wed Aug 30, 2017 11:15 pm
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm

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