Subject | Built-in DateDiff |
---|---|
Author | Aage Johansen |
Post date | 2009-07-09T18:20:06Z |
I had hoped that the DateDiff function would be useful to me, but it
works in way that surprised me a little.
E.g.
select datediff(month,cast('30.06.2000' as date),
cast('01.07.2000' as date))
from rdb$database
returns 1 (month),
and
select datediff(year,cast('30.12.2000' as date),
cast('02.01.2002' as date))
from rdb$database
returns 2 (years).
I understand what happens, but I had hoped for a function that would
return 0 months (i.e. less than 1 month) and 1 year (i.e. "1 <=
result < 2"). What I really need is to find "age" expressed as
"completed years" between two dates.
Is there another function I could use? I would prefer a no-UDF
solution, currently I always do this on the client.
Also, an example in the documentation (or explanation of how DateDiff
works) would be nice.
I believe that one upon a time I had a set of procedures for working
with dates, but I can no longer find it - or I may be misremembering
(maybe it is in a long retired pc).
--
Aage J.
works in way that surprised me a little.
E.g.
select datediff(month,cast('30.06.2000' as date),
cast('01.07.2000' as date))
from rdb$database
returns 1 (month),
and
select datediff(year,cast('30.12.2000' as date),
cast('02.01.2002' as date))
from rdb$database
returns 2 (years).
I understand what happens, but I had hoped for a function that would
return 0 months (i.e. less than 1 month) and 1 year (i.e. "1 <=
result < 2"). What I really need is to find "age" expressed as
"completed years" between two dates.
Is there another function I could use? I would prefer a no-UDF
solution, currently I always do this on the client.
Also, an example in the documentation (or explanation of how DateDiff
works) would be nice.
I believe that one upon a time I had a set of procedures for working
with dates, but I can no longer find it - or I may be misremembering
(maybe it is in a long retired pc).
--
Aage J.