[英]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.