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 

query for knowing specific date after some years

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


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Thu Jul 27, 2006 3:21 pm    Post subject: query for knowing specific date after some years Reply with quote

Hai All,

I am looking for a query which would tell me the date of my retirement Crying or Very sad assuming that when i joined the company on 2004-08-16 and my DOB being 1976-01-01 ,my age was 28 years 7 months and 15 days .
Code:

SELECT DATE('2004-08-16') - DATE('1976-01-01') FROM SYSIBM.SYSDUMMY1;

280715

If in my company the retirement age is 58 years then i would like to know by a optimised query which will give the retirement date as well number of years worked in the company.

Seems to be funny but i guess this would be a quick formula Very Happy
_________________
Shekar
Grow Technically
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 Jul 27, 2006 8:12 pm    Post subject: Reply with quote

shekar123,

Try this untested sql

Code:

SELECT DATE('1976-01-01')  AS BIRTH_DATE                             
      ,DATE('2004-08-16')  AS JOIN_DATE                             
      ,DATE('2004-08-16') + (DAYS(DATE('1976-01-01') + 58 YEARS) -   
                             DAYS('2004-08-16')) DAYS AS RETIRE_DATE
      ,DATE('1976-01-01') + 58 YEARS - DATE('2004-08-16')           
                            AS SERVICE_DURATION                     
FROM SYSIBM.SYSDUMMY1                                               
;                                                                   


If you have a EMP table with the following columns
Code:

EMP_NAME     
BIRTH_DATE   
JOIN_DATE   


then try this

Code:

SELECT EMP_NAME                                               
      ,BIRTH_DATE                                             
      ,JOIN_DATE                                               
      ,JOIN_DATE + (DAYS(BIRTH_DATE + 58 YEARS) -             
                    DAYS(JOIN_DATE)) DAYS  AS RETIRE_DATE     
      ,BIRTH_DATE + 58 YEARS - JOIN_DATE   AS SERVICE_DURATION
  FROM EMP                                                     
  ;             


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


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Thu Jul 27, 2006 9:09 pm    Post subject: Reply with quote

Kolusu,

You always prove that you are simply great and no need to test the query anywhere as it fetches all the expected values.Thanks. Very Happy
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
coolman
Intermediate


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Fri Jul 28, 2006 9:57 am    Post subject: Reply with quote

Kolusu,

If RETIREMENT DATE is 58 YEARS, then why have such a complex calculation with the JOIN DATE AND SERVICE DATE

Say for Example, Shekar123's birthday was 01-01-1976 and another person Chris's Birthday was 01-01-2000

So, Shekar would retire by 1976 + 58 = 2034 and Chris would retire by 2058

Why do we have to bring the JOIN DATE into the picture at all?

So, the query would be :

Code:


SELECT DATE('1976-01-01')  AS BIRTH_DATE                             
      ,DATE('2004-08-16')  AS JOIN_DATE                             
      ,DATE('1976-01-01') + 58 YEARS AS RETIRE_DATE
      ,DATE('1976-01-01') + 58 YEARS - DATE('2004-08-16')           
      AS SERVICE_DURATION                     
FROM SYSIBM.SYSDUMMY1                                     




Correct me If I'm not correct

Cheers.
________
Mercedes-Benz M113 engine history


Last edited by coolman on Sat Feb 05, 2011 1:45 am; edited 1 time in total
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Fri Jul 28, 2006 10:07 am    Post subject: Reply with quote

Coolman,

If you read my requirement , my query was to find out the retirment date if my company has limit to 58 years and to know how many years i worked.If my DOB was 1976-01-01 ,but i can join any year and my joining date would matter to calculate the number of years worked and the to know the retirement date.Hope i am clear.
_________________
Shekar
Grow Technically
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: Fri Jul 28, 2006 10:07 am    Post subject: Reply with quote

Quote:

Kolusu,

If RETIREMENT DATE is 58 YEARS, then why have such a complex calculation with the JOIN DATE AND SERVICE DATE


Simply put I am wrong. You can directly use birth as you mentioned.

Sorry

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


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Fri Jul 28, 2006 10:12 am    Post subject: Reply with quote

Shekar123,

You didn't get my point. JOINing date is immaterial when it comes to calculating the RETIREMENT DATE - JOINING date is required only when calculating the years of service at the company.

Hope this helps...
________
e cigarette


Last edited by coolman on Sat Feb 05, 2011 1:45 am; edited 1 time in total
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Fri Jul 28, 2006 11:42 am    Post subject: Reply with quote

coolman,

You need to know the Joining date to know the number of years worked in the company.Probably i did not put in the proper way in my previous post.
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
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