简体   繁体   中英

Convert Days to Years as in following format?

How to convert 1701 days to 4.660 years...

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:

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. If you want 4.660, can you explain how that is calculated?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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