SQL date format conversion from INT(yyyymmdd) type to date(mm/dd/yyyy)

user2963607 picture user2963607 · Nov 7, 2013 · Viewed 74.5k times · Source

I have a table with datekey column values(20120728,20120728...) in format of yyyymmdd as int type, I need to make them into date format of mm/dd/yyyy while writing select statement.

Answer

vhadalgi picture vhadalgi · Nov 7, 2013
DECLARE @date int;
SET @date = 20131107

SELECT CONVERT(date, CONVERT(varchar(8), @date), 112)