如何转换“dd / mm / yyyy” SQL Server中的字符串到datetime? [英] How to convert a "dd/mm/yyyy" string to datetime in SQL Server?

查看:274
本文介绍了如何转换“dd / mm / yyyy” SQL Server中的字符串到datetime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过这个



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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆