0

我有一个专栏date,它的类型是datetime带格式的YYYY-MM-DD HH:MM:SS.000

我的问题是某些日期有一个空格,而其他日期和时间之间有两个空格

例如。

2009-08-20 13:44:12.753
2009-08-20  13:44:12.753

即使当我尝试比较它们时时间相同,但由于空格,它们不匹配。我尝试使用该replace(date, ' ', '')功能,但这不能正确保持日期时间格式Aug2020091:44PM

我将如何比较这些日期以忽略空格但不影响日期时间本身?

4

1 回答 1

3

why would'nt you use

replace(date, '  ', ' ') 

I mean - replace just 2 white spaces into one

( it is not clear from my code but here it on pseudo )

 replace(date, '[ ][ ]', '[ ]')  //where [ ] is whitespace.

solution #2:

use this :

SELECT CAST('2009-08-20 13:44:12.753' AS DATETIME) --nevermind the spaces
SELECT CAST('2009-08-20       13:44:12.753' AS DATETIME)  --nevermind the spaces
于 2013-01-04T12:08:44.473 回答