tags:

views:

3114

answers:

2

How can I convert a varchar field of the form YYYYMMDD to a datetime in T-SQL?

Thank you.

+6  A: 
select convert(datetime, '20081030')
bobwienholt
I had to specify a format as well. SELECT CONVERT(datetime, '20081030', 102)
Allain Lalonde
Maybe that is dependent on your default settings... I guess it's better to specify a format no matter what.
bobwienholt
A: 

Use the CONVERT() function?

http://msdn.microsoft.com/en-us/library/ms187928.aspx

Joe The Software Developer