Skip to content
Advertisement

String to Date e.g. Jan 58 to 1958-01-01

I want to turn a short date in varchar into a date: ‘Short month name – YY’ format such as 'Apr-57' or 'Mar-2001' to an readable format for MSMS to turn it into a date such as 1957-04-01 or 2001-03-01.

Is there a shortcut I am missing? I’ve tried to convert, cast, and substring to alter the format to see if it would help. Thank you for any help in advance.

Advertisement

Answer

Does this help?

DECLARE @vc VARCHAR(50) = 'Mar-2001';
SET @VC = '01-' + @vc;
SELECT CAST(@VC AS DATE);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement