约会时间!从字符串中转换日期和/或时间时转换失败

问题描述 投票:0回答:1

我尝试将带有时间戳的列从nvarchar转换为datetime(因为我不确定通过将Excel导出到SQL Server不会丢失时间戳内的精度),但是该列仍不会转换,始终显示相同的错误

从字符串转换日期和/或时间时转换失败-转换

我尝试过

alter table X 
    alter column [Timestamp] datetime

而且我也尝试过:

convert(datetime, [Timestamp], 103)
try_convert(datetime, [Timestamp], 103)
cast ([Timestamp] as datetime)

仍然没有进展。

这是来自列的示例数据:

2019-02-13-13.01.05.6100000015
2019-02-18-13.10.46.4850000015

您能帮忙吗?

sql sql-server
1个回答
0
投票

您可以尝试以下方法:

select 
    try_convert(datetime2(7), 
                 STUFF(STUFF(REPLACE('2019-02-18-13.10.46.485000015','.',':'), 11, 1, ' '),20,1,'.')
               ,121)
© www.soinside.com 2019 - 2024. All rights reserved.