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
 

 

How to calculate start and end date

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

New User


Joined: 01 Dec 2006
Posts: 29
Location: S.A

PostPosted: Wed Aug 08, 2007 4:36 pm    Post subject: How to calculate start and end date
Reply with quote

Hi all,

I have to calculate the start date using DB2 if the time period is given.

For example, if somebody stayed at a location for 4 years and the left the location today ie 08-08-2008 , I have to get the date from when he started living at that location.
In this case, the answer (starting date) will be 08-08-2004.

I have been told by my seniors that there are some DB2 functions that can help you to get the start date if time period is given ( with ending date).

Can someone please help me.

Thanks
Vaibhav Rastogi
Back to top
View user's profile Send private message

ksk

Active User


Joined: 08 Jun 2006
Posts: 356
Location: New York

PostPosted: Wed Aug 08, 2007 5:10 pm    Post subject:
Reply with quote

Hi,

Using DAYS function calculate the number of days for the end date and deduct these number of days from the person stayed number of days. Again convert this scalar value into date using DATE function.

Might be this is not an optimized sloution. You can wait for other suggetions also.

Regards,
ksk
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Wed Aug 08, 2007 5:35 pm    Post subject:
Reply with quote

May be you can use

select end_date - x years... if you are using years to get the start date

select end_date - x months...if you are using months to get the start date

and KSK said..u can use days when u want to sustract days..

Thanks,
Prajesh
Back to top
View user's profile Send private message
vab987

New User


Joined: 01 Dec 2006
Posts: 29
Location: S.A

PostPosted: Wed Aug 08, 2007 5:45 pm    Post subject:
Reply with quote

but there is some DB2 function that calculates Start date with eaze. It also takes care for Leap year.

Please let me know if someone knows .
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Aug 08, 2007 5:54 pm    Post subject:
Reply with quote

vab987 wrote:
but there is some DB2 function that calculates Start date with eaze. It also takes care for Leap year.

Please let me know if someone knows .


Have you tried looking in the sql reference manual for date/time calculations.
Back to top
View user's profile Send private message
vab987

New User


Joined: 01 Dec 2006
Posts: 29
Location: S.A

PostPosted: Wed Aug 08, 2007 5:56 pm    Post subject:
Reply with quote

I don't have that manual. Can you please send me the link so that i can check it there.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Aug 08, 2007 6:25 pm    Post subject:
Reply with quote

Hello,

The SQL manual is linked to from the forum. Click on the "Manuals" link at the top of the web page.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 08, 2007 6:44 pm    Post subject: Re: How to calculate start and end date
Reply with quote

Here is the OS/390 and z/OS V7 SQL Reference

Start with 3.2 Scalar functions 3.2.17 DATE

Regarding the date functions, little has changed between V4 and V9.1

you can download this book to your pc for future reference
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Aug 08, 2007 7:14 pm    Post subject:
Reply with quote

vab987: Prajesh_v_p gave the correct solution, that is the DB2 stuff you need. It just isn't wrapped in COBOL or anything.

See this topic:
http://ibmmainframes.com/viewtopic.php?t=23406&highlight=db2+date
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 Date and time format in CICS Chandru3183 CICS 2 Sat Mar 18, 2017 12:46 pm
No new posts How to get current date -1 and curren... murali.andaluri DFSORT/ICETOOL 3 Wed Mar 08, 2017 2:09 pm
No new posts Overlay the system date Danielle.Filteau SYNCSORT 4 Fri Mar 03, 2017 1:16 am
No new posts Checking Current date vickey_dw DFSORT/ICETOOL 1 Wed Feb 08, 2017 11:14 pm
No new posts CICS START AND CANCEL blayek CICS 1 Wed Dec 07, 2016 3:27 am


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