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 

Adding a day to the invalid date.

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


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Thu Aug 11, 2005 10:29 am    Post subject: Adding a day to the invalid date. Reply with quote

Hi
I'm getting some invalid dates in the format YYYY-MM-DD. I need to add a day to this date and make it a valid date.

For example:
2005-06-31 should be changed to 2005-07-01
2005-02-31 should be changed to 2005-03-01


I'm using DB2 date function to check the invalid date like
Code:

SELECT DATE(:WS-INPUT-DATE)
   INTO :WS-OUT-DATE     
FROM SYSIBM.SYSDUMMY1     

If it returns -181 SQLCODE this is an invalid date. If so I need to add a day to it and make it a valid date. I know this can be done by checking the month and add one to month and then set day to 01. Also if it's December add 1 to year.But is there any built in function available for it?
Tried SET DATE but I think it expect a valid date as input
Appreciate any help on this.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Aug 11, 2005 11:05 am    Post subject: Reply with quote

ace,

try this untested code

Code:

MOVE SPACES       TO WS-VAL-DATE                         
MOVE '2005-06-31' TO WS-INV-DATE                         
                                                         
EXEC SQL                                                 
     SET :WS-VAL-DATE  = DATE(:WS-INV-DATE)               
END-EXEC                                                 
                                                         
EVALUATE SQLCODE                                         
    WHEN +0                                               
        CONTINUE                                         
    WHEN -181                                             
        MOVE '01'      TO WS-INV-DATE(9: 2)               
                                                         
        EXEC SQL                                             
            SET :WS-VAL-DATE = DATE(LAST_DAY(:WS-INV-DATE) + 1 DAY)
        END-EXEC             
                                 
    DISPLAY  WS-VAL-DATE
END-EVALUATE                                             
                                                         


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
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Thu Aug 11, 2005 2:00 pm    Post subject: Reply with quote

Thanks Kolusu
It worked...But one doubt. I'm getting the valid date as MM/DD/YYYY format where as my invalid date is YYYY-MM-DD.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Aug 11, 2005 2:14 pm    Post subject: Reply with quote

Quote:

It worked...But one doubt. I'm getting the valid date as MM/DD/YYYY format where as my invalid date is YYYY-MM-DD.


ace,

When your DB2 admin installed DB2 at your shop, there is an application programming defaults panel screen where he specifies values to be used as default values by the program preparation panels, the program preparation CLIST (DSNH), and the precompiler. They can also be used as defaults by other programs, such as Query Management Facility (QMF) and spufi also.

The date format can be ISO(yyyy-mm-dd), JIS(yyyy-mm-dd), USA(mm/dd/yyyy) , EUR( dd.mm.yyyy), LOCAL(your choice)

Depending on the default date format , DB2 validates the dates when inserting/updating a date field.

Now if your shop has defined USA format as the default date format , you will get the output in USA format.

check this link for Application programming defaults panel 2: DSNTIP4

http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/DSNIGH13/2.4.19?DT=20030515110323

So I suggest that you talk to your DBA and find out if you can override the pre-complier option.

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
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