-1

I have a bunch of dates in the format yyyymmdd without the "-" separated. What is the easiest way to change to yyyy-mm-dd format using only SQL with read access only. i.e 20111230 -> 2011-12-30

One line or optimal performance solution preferable that works in Microsoft SQL

Al_1999
  • 1
  • 2

1 Answers1

0
DECLARE @dtr VARCHAR(25) = '20111230'

SELECT CONVERT(char(10),CAST(@dtr AS DATE),126)

-- sqlserver 2012
SELECT FORMAT(CAST(@dtr AS DATE),'yyyy-MM-dd' )
Von Abanes
  • 706
  • 1
  • 6
  • 19