简体   繁体   English

varchar转换为datetime类型

[英]A varchar conversion to a datetime type

I wonder if with this conversion I have 100% certainty that the time for the my_date column will be properly converted, in general, that the whole date will look correct after the conversion. 我想知道如果通过这种转换我100%确定my_date列的时间将被正确转换,通常,整个日期在转换后看起来是正确的。

The date will always be correctly converted from the format dd-mm-yyyy HH:mm:ss to the format yyyy-mm-dd HH:mm:ss ? 日期将始终从格式dd-mm-yyyy HH:mm:ss正确转换为格式yyyy-mm-dd HH:mm:ss

What is the best conversion for this case? 这种情况的最佳转换是什么?

Below is an example for the problem described: 以下是所述问题的示例:

DECLARE @tmp TABLE (my_date VARCHAR(20))

INSERT INTO @tmp VALUES ('25-02-2019 19:30:12')
INSERT INTO @tmp VALUES ('01-03-2019 09:30:11')
INSERT INTO @tmp VALUES ('22-02-2018 19:42:12')
INSERT INTO @tmp VALUES ('01-11-2019 19:30:17')

SELECT CONVERT (DATETIME, my_date, 105) FROM @tmp
DECLARE @tmp TABLE (my_date VARCHAR(20))

INSERT INTO @tmp VALUES ('25-02-2019 19:30:12')
INSERT INTO @tmp VALUES ('01-03-2019 09:30:11')
INSERT INTO @tmp VALUES ('22-02-2018 19:42:12')
INSERT INTO @tmp VALUES ('01-11-2019 19:30:17')

SELECT CONVERT(NVARCHAR(20),CONVERT(DATETIME, my_date, 105),120) FROM @tmp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将varchar日期类型转换为datetime错误SQL - Conversion of a varchar date type to a datetime Error SQL SSIS中varchar数据类型到日期时间的转换 - Conversion of varchar data type to datetime in SSIS 将 varchar 数据类型转换为 datetime 数据类型的问题 - Issue with conversion of a varchar data type to a datetime data type 日期时间到varchar转换错误 - Datetime to varchar conversion error 从 varchar 到 Datetime 的转换 - Conversion from varchar to Datetime 日期时间转换错误 - 将 varchar 数据类型转换为日期时间数据类型导致值超出范围 - Datetime conversion error - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value 将varchar数据类型转换为日期时间。 超出范围的错误 - Conversion of a varchar data type to a datetime. Out-of-range error 将 varchar 数据类型转换为日期时间会引发超出范围的错误 - Conversion of a varchar data type to a datetime throws out-of-range error 将 varchar 数据类型转换为日期时间错误。 日期格式问题 - The conversion of a varchar data type to a datetime error. Issues with date format 从varchar数据类型到datetime数据类型的转换导致值超出范围。 日期时间错误 - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. Datetime error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM