A way to extract from a DateTime value data without seconds

前端 未结 8 2063
一向
一向 2020-11-30 13:39

I have an sql DateTime (ms sql server) and want to extract the same date without the seconds: e.g. 2011-11-22 12:14:58.000 to become: 2011-11

8条回答
  •  囚心锁ツ
    2020-11-30 14:12

    With a little fiddling around, this seems to work well:

    SELECT CAST(CONVERT(CHAR(17), bl.[time],113) AS varchar(17))
    

    Result given: 2011-11-22 12:14

    The exact way I'm using it in my query as part of the selection list :

    ,CAST(CONVERT(CHAR(17), bl.[time],113) AS varchar(17))
    + '    (UTC +0)' AS [TIME]
    

    Gives me the result: 15 Dec 2017 06:43 (UTC +0)

提交回复
热议问题