unable to change nvarchar to datetime type

Copper Contributor

Sajj_Mak_1-1691369147685.png

I am unable to change the nvarchar type to datetime type 2023-08-03T02:00:31+00:00 please help

2 Replies

@Sajj_Mak use only the valid left part together with CONVERT and the date sytle 126 = ISO,

 

DECLARE @date nvarchar(50) = N'2023-08-03T02:00:31+00:00'

SELECT CONVERT(datetime, LEFT(@date, 19), 126)

 

See CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn 

Thanks!