/* Created by Acmeware, Inc., All Rights Reserved                                       */
/*--------------------------------------------------------------------------------------*/
/* This function returns a computed Age in years between two dates.			*/
/*											*/
/* Parameters:										*/
/*	@DOB: Date of birth								*/
/*	@CheckDate: Date on which you want to check the Age				*/
/*											*/
/*	Return Value: Age (integer)							*/
/*											*/
/* Note: On birthdays, the Age is the new (higher) Age					*/
/*--------------------------------------------------------------------------------------*/
/*											*/
/* THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, 	*/
/* INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND 	*/
/* FITNESS FOR A PARTICULAR PURPOSE.							*/



CREATE         FUNCTION dbo.fxAge (@DOB datetime, @CheckDate datetime)  


RETURNS int AS  
BEGIN 
RETURN DATEDIFF(Year, @DOB, @CheckDate) - 
	CASE
		WHEN Month(@CheckDate) * 31 + Day(@CheckDate) >=  Month(@DOB) * 31 + Day(@DOB) THEN 0
		ELSE 1 
	END
END