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.
Asked
Active
Viewed 8.9k times
7

Cœur
- 37,241
- 25
- 195
- 267

user2963607
- 71
- 1
- 1
- 2
-
1What DBMS are you using? – jpw Nov 07 '13 at 07:03
-
googled "ms sql date formatting"? – LINQ2Vodka Nov 07 '13 at 07:03
2 Answers
19
DECLARE @date int;
SET @date = 20131107
SELECT CONVERT(date, CONVERT(varchar(8), @date), 112)

vhadalgi
- 7,027
- 6
- 38
- 67
-
hi, thanks for reply, after declaration you provided value, but i cant do that as i wil get lots of values from table – user2963607 Nov 07 '13 at 07:23
-
i made it to format of yyyy-mm-dd, i need to convert that to mm/dd/yyyy format, can you please help in this – user2963607 Nov 07 '13 at 07:41
-
this one works but i need column name in place of getdate(), thats throwing error – user2963607 Nov 07 '13 at 08:05
-
10
Please Try This
DECLARE @date int;
SET @date = 20120728
SELECT CONVERT(varchar(20), CONVERT(date, CONVERT(varchar(8), @date), 112),110)as datetime

code save
- 1,054
- 1
- 9
- 15
-
hi, this one is giving ans with - separated date i need adte in the format separated by '/', thanks for your reply, wil post my ans, it wont allow my reply to my question now – user2963607 Nov 07 '13 at 12:59
-
thanks that result can be separated by '/' ; you can place 103 insteed of 110 – code save Nov 07 '13 at 13:40