View previous topic :: View next topic |
Author |
Message |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Thu Jul 27, 2006 3:21 pm Post subject: query for knowing specific date after some years |
|
|
Hai All,
I am looking for a query which would tell me the date of my retirement 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 _________________ Shekar
Grow Technically |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12372 Topics: 75 Location: San Jose
|
Posted: Thu Jul 27, 2006 8:12 pm Post subject: |
|
|
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 |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Thu Jul 27, 2006 9:09 pm Post subject: |
|
|
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. _________________ Shekar
Grow Technically |
|
Back to top |
|
|
coolman Intermediate
Joined: 03 Jan 2003 Posts: 283 Topics: 27 Location: US
|
Posted: Fri Jul 28, 2006 9:57 am Post subject: |
|
|
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 |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Fri Jul 28, 2006 10:07 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12372 Topics: 75 Location: San Jose
|
Posted: Fri Jul 28, 2006 10:07 am Post subject: |
|
|
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 |
|
|
coolman Intermediate
Joined: 03 Jan 2003 Posts: 283 Topics: 27 Location: US
|
Posted: Fri Jul 28, 2006 10:12 am Post subject: |
|
|
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 |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Fri Jul 28, 2006 11:42 am Post subject: |
|
|
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 |
|
|
|
|