oscarito
oscarito

Reputation: 35

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

I want date to be displayed as yyyy-mm-dd. The value in the table for date is dd/mm/yyyy. I have run the query

select CONVERT(DATE, FORMDATE, 103) from UPDATELOG 

and i got error "Conversion failed when converting date and/or time from character string". Anyone can help me with this?

Upvotes: 0

Views: 87

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269483

This certainly looks like SQL Server. So, use try_convert() instead:

select TRY_CONVERT(DATE, FORMDATE, 103)
from UPDATELOG  ;

To get the values that fail, use:

select FORMDATE
from UPDATELOG
where TRY_CONVERT(DATE, FORMDATE, 103) is null

Upvotes: 1

Related Questions