Tuesday, April 3, 2012

cast a substring to a datetime in SQL

I found this online somewhere.

declare @columnA varchar(20)
set @columnA = '2011-05-11 11:04:53 CDT'
select CONVERT(datetime,substring(@columnA,1,len(@columnA)))

 
 

Also see: http://robbamforth.wordpress.com/2010/06/11/sql-date-formats-getdate-examples/

SET @daystamp = CONVERT(VARCHAR(8),GETDATE(),112)

No comments:

Post a Comment