SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON GO -- Convert 14 character string from YYYYMMDDHHMMSS fixed-length character format to datetime --------------------------------------------------------------------------------------- -- PROCEDURE: NMSstring_to_datetime -- DATE: Apr 21 2001 13:29PM -- AUTHOR: Paul Harris - IEALtd, Cardiff, UK -- DESCRIPTION: Fixed-string to datetime conversion. Can change to other fixed length formats quite easily. --------------------------------------------------------------------------------------- CREATE PROCEDURE sp_fixedstring_to_datetime @fixed_string varchar(14), @date_out datetime OUT AS DECLARE @time_str varchar(8),@date_str varchar(8) SELECT @date_str= @fixed_string, @time_str= substring(@fixed_string,9,2)+':'+substring(@fixed_string,11,2)+':'+substring(@fixed_string,13,2), @date_out= convert(datetime,@date_str,112)+convert(datetime,@time_str,108) GO SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON GO