Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mssql中将NVARCHAR值转换为dd mm yyyy hh:mm:ss AM/PM格式_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

如何在mssql中将NVARCHAR值转换为dd mm yyyy hh:mm:ss AM/PM格式

如何在mssql中将NVARCHAR值转换为dd mm yyyy hh:mm:ss AM/PM格式,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我知道我不是第一个问这个问题的人,我正在尝试将字符串值“18-05-2018 11:09:31 am”插入到mssql中数据类型为日期时间的列中 它将错误返回为 The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value. 我尝试了一些将字符串转换为datetime的解决方案,但无法获得预期的输出格式 我想将上面提到的字符串值的相同格式插入到has DATETI

我知道我不是第一个问这个问题的人,我正在尝试将字符串“18-05-2018 11:09:31 am”插入到mssql中数据类型为日期时间的列中

它将错误返回为

The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
我尝试了一些将字符串转换为datetime的解决方案,但无法获得预期的输出格式

我想将上面提到的字符串值的相同格式插入到has DATETIME格式列中


谁能帮我解决这个问题。

试试这样的方法:

DECLARE @StartDate nvarchar(100)
SET @StartDate='18-05-2018 11:09:31 PM'
SELECT CONVERT(DATETIME, @StartDate, 105)
您将得到以下结果:


我没有看到任何insert语句。只需插入一个ANSI投诉时间戳,例如
2018-05-18 11:09:31
,它应该可以工作,而无需使用转换。我希望数据的格式为18-05-2018 11:09:31 AMTry此格式:选择转换(varchar(50),@StartDate,105)作为日期时间