How to Get total working experience of an employee?

Hello Everybody,

--How to Get total working experience of an employee if only Date of joining column exits in your table.

Create table emp_details(
EmpName varchar(200),
DOJ smalldatetime -- Date of Joining

Insert into emp_details values('RAJA',convert(smalldatetime,'23/11/2002',103))

select * from emp_details


Declare @total_exp int
select @total_exp = DateDiff(year,DOJ,GETDATE()) from emp_Details where EmpName ='RAJA'
SELECT @total_Exp as total_Exp

(Note : you have to execute to all the codes exit within the ****** boundary.)

Thank You.



Author: Banshidhar Sahoo09 Apr 2009 Member Level: Gold   Points : 2

I have extended the DATEDIFF method to get exact difference in terms of months to find experience in number of years and months form.
Below is the modified code:

DECLARE @total_month INT, @year INT, @month INT;
SELECT @total_month = DATEDIFF(MONTH,DOJ,GETDATE()) FROM emp_Details WHERE EmpName ='RAJA';
SET @year = @total_month / 12;
SET @month = @total_month % 12;
PRINT 'Total experience is : ' + CONVERT(VARCHAR, @year) +' years and ' + CONVERT(VARCHAR, @month) + ' Months.';

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: