如何转换“dd / mm / yyyy” SQL Server中的字符串到datetime? [英] How to convert a "dd/mm/yyyy" string to datetime in SQL Server?
问题描述
我尝试过这个
SELECT convert(datetime,'23 / 07/2009',111)
/ p>
但是有这个错误
将varchar数据类型转换为datetime数据类型导致超出范围的值。
但是
SELECT convert(datetime,'07 / 23/2009',111)
虽然
如何修复第一个?
最后一个参数 CONVERT
似乎决定了用于解析的格式。请查看适用于CONVERT的MSDN文档。
111
- 您使用的是日本 yy / mm / dd
。
我想你正在寻找的是 103
,即 dd / mm / yyyy
。
所以你应该尝试:
SELECT convert(datetime,'23 / 07/2009',103)
I tried this
SELECT convert(datetime, '23/07/2009', 111)
but got this error
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
However
SELECT convert(datetime, '07/23/2009', 111)
is OK though
How to fix the 1st one ?
The last argument of CONVERT
seems to determine the format used for parsing. Consult MSDN docs for CONVERT.
111
- the one you are using is Japan yy/mm/dd
.
I guess the one you are looking for is 103
, that is dd/mm/yyyy
.
So you should try:
SELECT convert(datetime, '23/07/2009', 103)
这篇关于如何转换“dd / mm / yyyy” SQL Server中的字符串到datetime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!