日期:2014-05-17 浏览次数:20574 次
declare @a date,@b date,@c int
select @a='1995/4/15',@b='2012/11/06'
select @c=datediff(m,@a,@b)
select rtrim(@c/12)+'.'+rtrim(@c%12) '在職年月數'
/*
在職年月數
-------------------------
17.7
(1 row(s) affected)
*/
select ROUND(DATEDIFF(MONTH,'1995/4/15','2012/11/06')/12.0,1)
select CONVERT(VARCHAR(10),DATEDIFF(year,CONVERT(DATE,'1995/4/15'),CONVERT(DATE,'2012/11/06')))+'.'+CONVERT(VARCHAR(10),DATEDIFF(mm,CONVERT(DATE,'1995/4/15'),CONVERT(DATE,'2012/11/06'))-DATEDIFF(year,CONVERT(DATE,'1995/4/15'),CONVERT(DATE,'2012/11/06'))*12-1)
declare @begin date,@end date
sset @begin='1995/4/15',@end='2012/11/06'
select cast(datediff(year,@begin,@end) as varchar(10))+'.'+cast(datediff(mm,@begin,@end)%12-1 as varchar(10))
/*
-------
17.6
*/