There are many ways to write such a function. I present two.
declare @strdate varchar(20)
set @strdate='20020304113200'
-- Function 1
Select DateTime1=
convert(datetime,left(@strdate,8),112) +
convert(datetime,stuff(stuff(right(@strdate,6),5,0,':'),3,0,':'),108)
-- Function 2
set @strdate=stuff(stuff(@strdate,13,0,':'),11,0,':')
set @strdate=stuff(stuff(stuff(@strdate,9,0,' '),7,0,'/'),5,0,'/')
select DateTime2=convert(datetime,@strdate)
I've created a page explaining "Date Handling in SQL Server." I willl post it as a FAQ in this forum when the FAQ submision process is fixed. In the meantime you canview it at...
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.