After importing date strings in dd.(m)m.yyyy
format from .csv I don't seem to be able to convert them into dates.
Using CONVERT (date, DATE_COLUMN, 104)
causes an error:
Conversion failed when converting date and/or time from character string.
However, if I try to convert values that I copied from the column selection output (CONVERT (date, '20.5.2018', 104)
), the code works fine for each single value in the column.
Trimming the strings didn't work. I have also tried manually rewriting the date string in the source file, but the result is the same.
To summarize (using 1 example value):
select CONVERT(date, DATE_COLUMN, 104)
from dbo.table
returns:
Conversion failed when converting date and/or time from character string.
select DATE_COLUMN
from dbo.table
returns: 20.5.2018
select CONVERT(date,'20.5.2018', 104)
returns: '2018-5-20'
I would expect SQL Server to treat each convert the same way. While there is a workaround (splitting the string into dateparts and combining them into date), I don't understand why the conversion fails in the first place. Any help appreciated.