Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 649
user2963607 Avatar asked Nov 07 '13 07:11

user2963607


2 Answers

DECLARE @date int;
SET @date = 20131107

SELECT CONVERT(date, CONVERT(varchar(8), @date), 112)
like image 189
vhadalgi Avatar answered Oct 13 '22 14:10

vhadalgi


Please Try This

DECLARE @date int;
SET @date = 20120728    
SELECT CONVERT(varchar(20), CONVERT(date, CONVERT(varchar(8), @date), 112),110)as datetime
like image 43
code save Avatar answered Oct 13 '22 13:10

code save