Reputation: 9395
I have the number 20080331.
I need to cast/convert this into a datetime so I can do a date comparison within the database. How will i go about converting this number. Using CONVERT(DATETIME, Value) does not seem to work.
Upvotes: 4
Views: 20597
Reputation: 175748
You need to cast to a character type first;
select cast(cast(20080331 as varchar(8)) as datetime)
>>2008-03-31 00:00:00.000
Upvotes: 4