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

175 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

The working solution is:

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

or

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

use REPLACE instead of CONVERT Function

 REPLACE(LOCALDATE_T,'\','/')