i am consuming an API and part of the response is a date value ( 25-11-2023 13:33:46+0000 ) that was stored as a string.
I am trying to convert this ( 25-11-2023 13:33:46+0000 ) to datetime or just date in my sql server database and i get the error message in the title.
I have used Cast, Convert and i still get the error when when converting.
cast('25-11-2023 13:33:46+0000' as date) convert(date, '25-11-2023 13:33:46+0000')
i will appreciate an assitance please
Hi, why won't you substring your String datetime then cast is to date?
i.e:
SELECT CONVERT(DATE,SUBSTRING('25-11-2023 13:33:46+0000',0, 11),105)
Convert takes date in pattern "yyyy-MM-dd", that's why it is showing an error on converting, or you can add "105" as a parameter which corresponds to the format "dd-MM-yyyy".
[test it][1]