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
 
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: 6968
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 Validate the Date girishb2 DFSORT/ICETOOL 9 Tue Sep 19, 2017 1:12 am
No new posts Creating ISPF Screens with Scrname vi... Albireo20 TSO/ISPF 9 Tue Sep 05, 2017 4:24 pm
No new posts Julian Date to CICS ABSTTIME blayek CICS 3 Wed Aug 30, 2017 11:15 pm
No new posts Wanted to calculate TRK when i have B... Balu5491 JCL & VSAM 9 Wed Jul 19, 2017 5:43 pm
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm

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