How to calculate years of and months of experience in different columns?

时间:2018-12-27 12:55:23

标签: sql oracle

say this column (d) is the date of joining and I want to calculate years of experience and months in different columns. I really need help on that.

thanks in advance.

2 个答案:

答案 0 :(得分:0)

假设使用SQL Server,并根据@Damien_The_Unbeliever的注释,这取决于您要如何使用数据。还要假设它是查询的一部分,下面是一些可以完成此工作的T-SQL:

declare @d datetime = dateadd(mm,-6,getdate())

select  
    datediff(yy,@d,getdate()) Years, 
    datediff(mm,@d,getdate())- (datediff(yy,@d,getdate())*12) Months

答案 1 :(得分:0)

尝试此查询

 select @JoinDate ,Datediff(yy, @JoinDate,getdate()) [year] ,Datediff(month, @JoinDate,getdate())%12 [month]