Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE @String VARCHAR(10);
- DECLARE @DateValue DATE;
- SET @String = '250809';
- -- Convert your undelimited string DDMMYY into a DATE
- -- First: Add / between the string parts.
- SET @STRING = SUBSTRING(@String,1,2)+'/'+
- SUBSTRING(@String,3,2)+'/'+SUBSTRING(@String,5,2);
- -- Second: Convert using STYLE 3 to get DD/MM/YY interpretation
- SELECT @DateValue = CONVERT(Date, @String, 3);
- -- Using the DATE
- -- Select the value in default Year-Month-Day
- SELECT @DateValue AS DefaultFormat;
- -- Select the value formatted as dd/mm/yy
- SELECT CONVERT(VARCHAR(20),@DateValue,3) AS [DD/MM/YY];
- DefaultFormat
- -------------
- 2009-08-25
- DD/MM/YY
- --------
- 25/08/09
- DECLARE @d CHAR(6) = '250909';
- SELECT DATEFROMPARTS('20'+RIGHT(@d,2),SUBSTRING(@d,3,2),LEFT(@d,2));
Add Comment
Please, Sign In to add comment