Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Friends,

I have Date of Birth as a column in Table and I want to get the year when the staff will retires from the company
Eg - My DOB is 20-01-1988
My retirement Year will be = 2048
How to get this from SQL query. Kindly guide me on the same.
Posted

try below t-sql code :

SQL
SELECT YEAR(DATEADD(YY, 60,YourBirthDate)) from EmpMast
 
Share this answer
 
v2
So basically you need to get your year of retirement from your birth year.
By your statement it seems that you put 60Years age criteria for retirement. So in SQL you need to add 60Year in Date of birthDate and you will get retirement year.
check following code snnipet

SQL
SELECT DATEADD(yyyy,60,DOB)AS RETIREMENT_YEAR FROM EMP 


here we add 60 year to date of birth

hope it helps
 
Share this answer
 
v2
Comments
Arunprasath Natarajan 10-Nov-12 0:24am    
Tan q dr, It works fine and feel ashamed of my knowledge power.
User DATEADD(datepart,number,date) function

Where date is a valid date expression and number is the number of interval you want to add. The number can either be positive, for dates in the future, or negative, for dates in the past.

datepart can be one of the following:
datepart	Abbreviation
year	         yy, yyyy
quarter	         qq, q
month	         mm, m
dayofyear	dy, y
day	        dd, d
week	        wk, ww
weekday	        dw, w
hour	        hh
minute	        mi, n
second	        ss, s
millisecond	ms
microsecond	mcs
nanosecond	ns


eg: DATEADD(year,60,DOB)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900