TSQL:字符串错误的日期时间 [英] TSQL: datetime from character string error

查看:70
本文介绍了TSQL:字符串错误的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些与此相关的帖子,但是我对TSQL还是很陌生,所以我无法理解它们,所以请原谅。

There are some posts related to this but I'm so new to TSQL that I cannot make sense of them so please excuse me.

我的过程有:

    BEGIN TRY

        INSERT INTO  dbo.myprocedure(
         Mydate

     )
     VALUES(
     CONVERT(DATETIME, @mydate, 102)
)

如果我这样执行:

EXEC mydbo.dbo.myprocedure @mydate = 'May 8 2012 9:21AM'  

我收到此错误:
从字符串转换日期时间时转换失败。

I get this error: Conversion failed when converting datetime from character string.

我该如何解决?

感谢一百万

推荐答案

如果您查看 CONVERT文档,您会看到格式102是ANSI格式,或者 yyyy.mm.dd 。因此,传递类似 2012.05.08 之类的日期应该可以。

If you look at the documentation for CONVERT, you'll see that format 102 is the ANSI format, or yyyy.mm.dd. So passing a date like 2012.05.08 should work.

看起来像 2012.05。 08 9:41 2012.05.08 9:41 AM 也可以使用,但这超出了文档格式。

It looks like 2012.05.08 9:41 and 2012.05.08 9:41AM will work too, but that's outside the documented format.

这篇关于TSQL:字符串错误的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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