USE [GoDb]
GO

/****** Object: UserDefinedFunction [dbo].[LG_INTTODATE] Script Date: 15.5.2015 18:27:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[LG_INTTODATE](@LDATE INT)
RETURNS DATETIME
AS
BEGIN
DECLARE @DATE DATETIME,
@DD INT,
@MM INT,
@YYYY INT,
@DATESTR VARCHAR(12)
SELECT @DD = ((@LDATE%65536)/256)
SELECT @MM = (@LDATE%65536)%256
SELECT @YYYY = (@LDATE/65536)
SELECT @DATESTR = CAST(@DD AS VARCHAR(2))+'-'+
CAST(@MM AS VARCHAR(2))+'-'+
CAST(@YYYY AS VARCHAR(4))
SELECT @DATE = CONVERT(DATETIME,@DATESTR,102)
RETURN(@DATE)
END

GO


USE [GoDb]
GO

/****** Object: UserDefinedFunction [dbo].[LG_INTTOTIME] Script Date: 15.5.2015 18:27:37 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON GO

CREATE FUNCTION [dbo].[LG_INTTOTIME](@LDATE INT) RETURNS VARCHAR(12) AS BEGIN DECLARE @TIME DATETIME, @HH INT, @MM INT, @SS INT, @TIMESTR VARCHAR(12), @RETSTR VARCHAR(12) SELECT @HH = (@LDATE-(@LDATE%65536))/65536/256 SELECT @MM = ((@LDATE-(@LDATE%65536))/65536-((@LDATE-(@LDATE%65536))/65536/256)*256) SELECT @SS = (((@LDATE%65536)-((@LDATE%65536)%256))/256) SELECT @TIMESTR = CAST(@HH AS VARCHAR(2))+':'+ CAST(@MM AS VARCHAR(2))+':'+ CAST(@SS AS VARCHAR(2)) SELECT @TIME = CONVERT(DATETIME,@TIMESTR,101) SELECT @RETSTR = CONVERT(VARCHAR,@TIME,108) RETURN(@RETSTR) END

USE [GoDb] GO

/****** Object: UserDefinedFunction [dbo].[LG_TIMETOINT] Script Date: 15.5.2015 18:27:42 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[LG_TIMETOINT](@HH INT,@MM INT,@SS INT)
RETURNS INT
AS
BEGIN
DECLARE @TIME INT
SELECT @TIME = (@HH65536256+@MM65536+@SS256)
RETURN(@TIME)
END

GO