MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Conversion of CYYMMDD format to DATE format in DB2

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
aniket
Beginner


Joined: 27 May 2005
Posts: 14
Topics: 8

PostPosted: Fri Jan 27, 2006 7:19 am    Post subject: Conversion of CYYMMDD format to DATE format in DB2 Reply with quote

Hi,
I want to calculate no of days difference between current date and a date field in DB2 table. This field is declared as char(7) and in CYYMMDD format. e.g. Today's date in table will be 2060127.

Currently I am using following syntax:
Code:

  (DAYS(CURRENT DATE) -
 DAYS(DATE('20'||SUBSTR(PD.WRIT_DTE,2,2)||'-'||
 SUBSTR(PD.WRIT_DTE,4,2)||'-'||SUBSTR(PD.WRIT_DTE,6,2))))

But the problem here is that century field may either be 1 or 2 and accordingly I have to concatenate 19 or 20 in above query.

Can you please help me out in this regard? Is there any way to convert CYYMMDD format directly to DATE format?
_________________
Thanks,

Aniket.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Fri Jan 27, 2006 9:36 am    Post subject: Reply with quote

aniket,

Try this . This query will take care of both 19 and 20 in the century part

Code:

SELECT DAYS(CURRENT DATE) -                 
       DAYS(DATE((CASE SUBSTR(WRIT_DTE,1,1) 
                  WHEN '1' THEN CHAR('19')       
                  WHEN '2' THEN CHAR('20')       
                  ELSE CHAR('20') END) ||         
                  SUBSTR(WRIT_DTE,2,2) ||         
                  CHAR('-')            ||         
                  SUBSTR(WRIT_DTE,4,2) ||         
                  CHAR('-')            ||         
                  SUBSTR(WRIT_DTE,6,2)))         
 FROM TABLE
 ;   


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
aniket
Beginner


Joined: 27 May 2005
Posts: 14
Topics: 8

PostPosted: Fri Jan 27, 2006 10:09 am    Post subject: Reply with quote

Thank you very much Kolusu...
_________________
Thanks,

Aniket.
Back to top
View user's profile Send private message
aniket
Beginner


Joined: 27 May 2005
Posts: 14
Topics: 8

PostPosted: Fri Jan 27, 2006 11:27 am    Post subject: Reply with quote

Hi Kolusu,

I tried out with following query in SPUFI as I need 30 days difference as one of criterion:
[code:1:fc0b8af72c]
SELECT
PT.POLICY_NO
FROM
DB2PADM.VLS_POLICY_TRANS PT,
DB2PADM.VLS_POLICY_TEMP_DT PD
WHERE
PT.POLICY_NO = PD.POLICY_NO AND
PD.POLICY_NO = '4049197' AND
PT.BILL_CLASS IN ('A','B','C') AND
PT.STATUS = 49 AND
PT.FREEZE = 'A' AND
PD.WRIT_DTE
_________________
Thanks,

Aniket.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Fri Jan 27, 2006 1:30 pm    Post subject: Reply with quote

Aniket,

May be WRIT_DTE has NULL values. In that case you will get an error.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group