I have posted about Creating DATETIME value from integer DATE and integer TIME where I have shown you various methods to create datetime value from integer date and time. Well. Did you know that in MSDB database there is a system function named agent_datetime that does the same thing?
select msdb.dbo.agent_datetime(20011129,211223)
----------------------- 2001-11-29 21:12:23.000
CREATE FUNCTION agent_datetime(@date int, @time int) RETURNS DATETIME AS BEGIN RETURN ( CONVERT(DATETIME, CONVERT(NVARCHAR(4),@date / 10000) + N'-' + CONVERT(NVARCHAR(2),(@date % 10000)/100) + N'-' + CONVERT(NVARCHAR(2),@date % 100) + N' ' + CONVERT(NVARCHAR(2),@time / 10000) + N':' + CONVERT(NVARCHAR(2),(@time % 10000)/100) + N':' + CONVERT(NVARCHAR(2),@time % 100), 120) ) END
Tags: