Monday, January 28, 2013

Code Snippet


It typical in some organizations to combine the month and a year together like 201211, the following code snippet converts it to a datetime format

declare @my varchar(6)
set @my = 201212
declare @temp datetime
set @temp = cast(substring(@my,5,2) +'/01/' +substring(@my, 1,4) as datetime)
select @temp
-- result: 2012-12-01 00:00:00.000

Back to Google Blogger

Hello World!!