Most optimal way to convert to date

Posted by IMHO on Stack Overflow See other posts from Stack Overflow or by IMHO
Published on 2010-05-06T13:22:50Z Indexed on 2010/05/06 13:28 UTC
Read the original article Hit count: 266

Filed under:
|
|
|

I have legacy system where all date fields are maintained in YMD format. Example:

20101123
this is date: 11/23/2010

I'm looking for most optimal way to convert from number to date field.

Here is what I came up with:

declare @ymd int

set @ymd = 20101122

select @ymd, convert(datetime, cast(@ymd as varchar(100)), 112)

This is pretty good solution but I'm wandering if someone has better way doing it

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql