Search code examples
sqlsql-serverdatetype-conversionvarchar

Convert varchar "18-MAR-13" to Date in SQL Server


Varchar value "18-MAR-13" needs to be smartly converted to date as "18-03-2013" in DD-MM-YYYY format.

None of CAST, TRY_CAST, CONVERT, TRY_CONVERT worked.

I have tried with CONCAT, but it got too long.


Solution

  • Use convert with the appropriate style - assuming 13 means 2013, if not clarify in the question.

    select Convert(varchar(10),Convert(date, '18-MAR-13'), 105)