USE [ARSystem]
GO
/****** Object:  UserDefinedFunction [dbo].[datetime_to_DateOnlyInt]    Script Date: 10/02/2007 12:26:48 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

CREATE FUNCTION [dbo].[datetime_to_DateOnlyInt] (@sql_date datetime)
RETURNS INT AS
BEGIN
	DECLARE @dateint	INT;

--	smalldatetime type beginning range is 01/01/1900
--	Remedy Date-only integer value for 01/01/1900 is 2415021
--	SET @dateint = DATEDIFF(dd,'19000101',@sql_date) + 2415021;

--	datetime type beginning range is 01/01/1753
--	Remedy Date-only integer value for 01/01/1753 is 2361331
	SET @dateint = DATEDIFF(dd,'17530101',@sql_date) + 2361331;

	RETURN @dateint;
END

