Hello,
I am trying to calculate an age in terms of years and express the result as
a float, such as 3.75 years or 5.33333 years etc. I have tried things
like...
CONVERT(float, DATEDIFF(d, MyStartDate, getdate()) ) /365 as YearsOld
But this gives results as whole numbers like 3.0 and 5.0. What do I need to
change in the syntax? (I realize that dividing by 365 is inaccurate, but it
is close enough for my purposes). Thanks in advance.Sorry for dup - my newsreader gave me an error and it didnt look like the
first one posted.
"Mark Hoffy" <mark@.here.com> wrote in message
news:vnuIe.291$Zo3.240@.fe03.lga...
> Hello,
> I am trying to calculate an age in terms of years and express the result
as
> a float, such as 3.75 years or 5.33333 years etc. I have tried things
> like...
> CONVERT(float, DATEDIFF(d, MyStartDate, getdate()) ) /365 as YearsOld
> But this gives results as whole numbers like 3.0 and 5.0. What do I need
to
> change in the syntax? (I realize that dividing by 365 is inaccurate, but
it
> is close enough for my purposes). Thanks in advance.
>|||Mark,
I can't reproduce the problem you are having:
declare @.t table (
MyStartDate datetime
)
insert into @.t values ('20030102')
select CONVERT(float, DATEDIFF(d, MyStartDate, getdate()) ) /365 as YearsOld
from @.t
Result:
YearsOld
----
2.5890410958904111
Can you possibly post a complete script that demonstrates the problem?
Steve Kass
Drew University
Mark Hoffy wrote:
>Hello,
>I am trying to calculate an age in terms of years and express the result as
>a float, such as 3.75 years or 5.33333 years etc. I have tried things
>like...
>CONVERT(float, DATEDIFF(d, MyStartDate, getdate()) ) /365 as YearsOld
>But this gives results as whole numbers like 3.0 and 5.0. What do I need t
o
>change in the syntax? (I realize that dividing by 365 is inaccurate, but i
t
>is close enough for my purposes). Thanks in advance.
>
>|||See other thread for reply.
SK
Mark Hoffy wrote:
>Sorry for dup - my newsreader gave me an error and it didnt look like the
>first one posted.
>"Mark Hoffy" <mark@.here.com> wrote in message
>news:vnuIe.291$Zo3.240@.fe03.lga...
>
>as
>
>to
>
>it
>
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment