I have made a function in SQL to calculate the Age from the Birthday and it is like this:
FUNCTION [dbo].[GetAge] (@birthday datetime, @date datetime)
RETURNS int
AS
BEGIN
return datediff(SECOND, @birthday, @date) / (365.23076923074 * 24 * 60 * 60)
END
The birthday is of format : 1963-01-01 00:00:00.000
My problem is that when I call the function like this :
SELECT dbo.GetAge(birthday, '2014-12-17 00:00:00')
FROM [dbo].[Users]
GO
it says:
Msg 535, Level 16, State 0, Line 3
The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
BUT I call the same function with a date like :
SELECT dbo.GetAge(birthday, '1963-01-01 00:00:00')
FROM [dbo].[Users]
GO
I get the results.. So I don't understand what is the problem.
Pls help me and thank you in advance