Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
hanifikri
Starting Member
14 Posts |
Posted - 2007-02-15 : 21:58:46
|
Hi, I want to calculate Years in Service between 2 dates. Example: Current Date: 16/02/2007 Employment Date: 01/10/1992 Years in Service = (Employment Date - Current Date) The answer should be 14.++. If i used datediff(year,employment date,current date) function i will get 15 years. This is not the right answer.Please help.Thanks. |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-15 : 23:10:42
|
[code]datediff(year month, employment date, current date) / 12.0[/code] KH |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-15 : 23:14:39
|
F_AGE_IN_YEARS returns INT. Think hanifikri wanted the year diff including the decimals KH |
 |
|
hanifikri
Starting Member
14 Posts |
Posted - 2007-02-15 : 23:26:45
|
I get the answer that i want.Thanks to both of you. |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-02-15 : 23:29:17
|
quote: Originally posted by khtan F_AGE_IN_YEARS returns INT. Think hanifikri wanted the year diff including the decimals KH
Hard to tell exactly what he wanted. If that is what he wants, the datediff you posted doesn't really do it either. For example:select Years=datediff(month,'20070131','20070201')/12.0Years ------------------- .083333 But .0027397 would be closer to correct, 1/365.In any case, what he asked for is "Years in Service between 2 dates", and F_AGE_IN_YEARS will return the whole number of years.CODO ERGO SUM |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-16 : 00:55:36
|
quote: I get the answer that i want.
Anyway, whatever he is asking, he got the answer he wanted.  KH |
 |
|
|
|
|
|
|