Skip to content
Advertisement

How to convert MM/YYYY/DD format string to DATE in SQL Server?

I have a column for which I need to convert the data to DATE format. I receive below error whenever I encounter the data ‘MM/YYYY/DD’ format, but it works fine for other formats.

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

Sample data:

SELECT ISDATE('05/2020/29') returns 1 but CAST or CONVERT functions fail.

Advertisement

Answer

That’s a weird format. I would recommend datefromparts():

Demo on DB Fiddle:

| mydate     |
| :--------- |
| 2020-05-29 |
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement