Subject Re: [firebird-support] dates difference function
Author Richard Wesley
On Apr 3, 2007, at 03:32, Alejandro Garcia wrote:

> Hi! I'm trying to calculate a dates difference in a stored
> procedure in InterBase 7.5: given two dates in dd/mm/yyyy format I
> need its difference in days,
> like this one in SQL 2000:
>
> set @Days = (SELECT DATEDIFF(DAY,@val1, @val2))
>
> is there a predefined function to do that? couldn't find it in
> the Language Reference nor Data Reference..

For DAY the solution given elsewhere in the thread. If you want
other date parts, FreeAdHocUDFLib defines them for all except
quarter, and that one is pretty simple too:

((EXTRACT(YEAR FROM @val2) * 4 + F_QUARTER(@val2)) - (EXTRACT(YEAR
FROM @val1) * 4 + F_QUARTER(@val1)))

You can also do similar tricks with extract for YEAR and MONTH, but
when you get down into week and time values it gets uglier to do it
in line.

HTH,
________________________________________________________
Richard Wesley Senior Software Developer Tableau
Software
Visit: http://www.trytableau.com/now.html