CREATE FUNCTION dbo.JDE2DATE(@jde DECIMAL(6, 0))
RETURNS DATETIME
WITH RETURNS NULL ON NULL INPUT
AS
BEGIN
	RETURN	DATEADD(DAY, @jde % 1000, DATEADD(YEAR, @jde / 1000, -1));
END

CREATE FUNCTION dbo.DATE2JDE(@dt DATETIME)
RETURNS DECIMAL(6, 0)
WITH RETURNS NULL ON NULL INPUT
AS
BEGIN
	RETURN	1000 * DATEPART(YEAR, @dt) - 1900000 + DATEPART(DAYOFYEAR, @dt);
END
