简体   繁体   English

将天转换为年,格式如下?

[英]Convert Days to Years as in following format?

How to convert 1701 days to 4.660 years... 如何将1701天转换为4.660年...

I used this following query but i get only Year .... 我使用以下查询,但我只得到年份....

My query: 我的查询:

SELECT DATEDIFF(YEAR , B.emp_join_date, GETDATE())  from employee B

Output I get: 我得到的输出:

4

Expected output: 预期产量:

4.660 

How i get the result? 我如何得到结果?

I think the simplest way is to use the approximation of 365.25 days per year: 我认为最简单的方法是每年使用大约365.25天:

select 1701 / 365.25

In your case, this would be: 在您的情况下,这将是:

SELECT DATEDIFF(day, e.emp_join_date, GETDATE()) / 365.25
FROM employee e;

This actually returns 4.657. 这实际上返回4.657。 If you want 4.660, can you explain how that is calculated? 如果要4.660,可以解释一下它的计算方式吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM