IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Regd the Date logic


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
cvijay784
Warnings : 1

New User


Joined: 18 Jun 2008
Posts: 54
Location: Colombo

PostPosted: Mon May 18, 2009 12:30 pm
Reply with quote

Hi,

My current requirement is to extract records between the particular months, i.e to extract the data from staring of the month to end of the some other month..

Example Query:
Select *
from EMP_TABLE
where EMP_DATA BETWEEN :WS-START-DATE AND :WS-END-DATE

Here i am altering the start & end dates according to the current system date..but day fields are hardcoded as '01' and '31' for WS-START-DATE AND WS-END-DATE respectively..

Since 31st Apr is not a valid date ..am getting -181 error for the above mentioned query..

How can i include a logic to overcome my problem instead of hardcoding the day based on the month?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 18, 2009 1:31 pm
Reply with quote

How about using LAST_DAY(DATE) scalar function in DB2?
Back to top
View user's profile Send private message
cvijay784
Warnings : 1

New User


Joined: 18 Jun 2008
Posts: 54
Location: Colombo

PostPosted: Mon May 18, 2009 2:23 pm
Reply with quote

Yes..i think this LAST_DAY function will be useful for my req with little bit modification..

Ex:

Here WS-START-DATE = 2009-04-01

EXEC SQL
SET :WS-END-DATE = LAST_DAY(:WS-START-DATE)
END-EXEC.

Now WS-END-DATE = 2009-04-30

And i think for leap years also it should work to give the proper end-date

Thanks for the reply..
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 18, 2009 2:39 pm
Reply with quote

Welcome.... icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
No new posts Fetch data from programs execute (dat... DB2 3
Search our Forums:

Back to Top