Search code examples
mysqlsqlsql-serverdatestring-to-datetime

Convert SQL date varchar(512) to dd/MM/yyyy


When I want to "translate" a Ndate figure into dd/MM/yyyy I use this

convert(varchar(16),dateadd(day, d.Field_Date, '01-01-1970'),103)

But I have a field that's VARCHAR(512) with that very format, and I'd like to convert that string to a date format.

Could you (yes, you :-)) tell me how to do it in SQL Server language?

Thank you.


Solution

  • Why not just use the same query:

    declare @date varchar(512) = '03/11/2015'
    
    Select CONVERT(date, @date, 103)
    

    103 is the correct style to use with Convert for British/French dates (dd/mm/yyyy)

    Output as date:

    2015-11-03