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 |
|
jogin malathi
Posting Yak Master
117 Posts |
Posted - 2007-04-25 : 05:23:06
|
| hiselect datediff(m,'3/5/2003',getdate as experience output isExperience ----------49select (datediff(m,'3/5/2003',getdate()))/12 as experience output isExperience ----------4but 49/12 is 4.08333=4.1how i can get thisActually my task is to output as years.monthsThanks in advanceMalathi Rao |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-25 : 05:28:25
|
datediff returns integer, integer divide by integer will give you an integer.using 12.0 will convert the result to decimalselect (datediff(m,'3/5/2003',getdate()))/12.0 as experience KH |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-04-25 : 05:33:38
|
| select cast(datediff(m,'3/5/2003',getdate()) as float)/12 as experience |
 |
|
|
jogin malathi
Posting Yak Master
117 Posts |
Posted - 2007-04-25 : 06:38:02
|
quote: Originally posted by pbguy select cast(datediff(m,'3/5/2003',getdate()) as float)/12 as experience
ya it's okbut the o/p of u r query is 4.083333 'but i want as 4.1Malathi Rao |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-25 : 06:42:13
|
Round the output to 1 decimal places.Select round((datediff(m,'3/5/2003',getdate()))/12.0,1) as experience Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-25 : 06:43:00
|
or another solution is:select convert(numeric(25,1), (datediff(m,'3/5/2003',getdate()))/12.0) as experience Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
naveen901
Starting Member
2 Posts |
Posted - 2007-04-26 : 04:08:33
|
quote: Originally posted by jogin malathi hiselect datediff(m,'3/5/2003',getdate as experience output isExperience ----------49select (datediff(m,'3/5/2003',getdate()))/12 as experience output isExperience ----------4but 49/12 is 4.08333=4.1how i can get thisActually my task is to output as years.monthsThanks in advanceMalathi Rao
hitry thisSelect (datediff(m,'3/5/2003',getdate()))/12.0 as experiencethanksnaveen. |
 |
|
|
|
|
|
|
|