Search code examples
sql-server-2008t-sqlssmsssms-2014

T SQL SSMS Convert Varchar DD\MM\YYYY to Date format


I have a VARCHAR(10) data type column with date in DD\MM\YYYY format. I tried using convert(datetime,LOCALDATE_T,103) and much more. However throws me an error of

Conversion failed when converting date and/or time from character string.

I am unsure if my query could read DD\MM\YYYY. I have usually converted column from DD/MM/YYYY format i.e. / but not this \

Request your assistance.


Solution

  • The working solution is:

    CONVERT(datetime, REPLACE(LOCALDATE_T, '\', '/'), 103)
    

    or

    CAST(REPLACE(LOCALDATE_T, '\', '/') as date)