TSQL: datetime from character string error

前端 未结 3 1366
北恋
北恋 2021-01-28 06:20

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.

My procedure has:

    BEGIN TRY

              


        
相关标签:
3条回答
  • 2021-01-28 07:00

    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.

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

    0 讨论(0)
  • 2021-01-28 07:07

    Change CONVERT(DATETIME, @mydate, 102) to CONVERT(DATETIME, @mydate, 100)

    or just CONVERT(DATETIME, @mydate)

    reference to CAST and CONVERT and http://www.sqlusa.com/bestpractices/datetimeconversion/ on MSDN

    0 讨论(0)
  • 2021-01-28 07:13

    Maybe something like this:

    EXEC mydbo.dbo.myprocedure @mydate = '2012/05/08 09:21:00'  
    
    0 讨论(0)
提交回复
热议问题