How to convert a datetime to string in T-SQL

前端 未结 9 1390
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 03:19

I\'m surprised not to be able to find this question here already.

I have a date time var and I want to convert it to a string so that I can append it to another stri

9条回答
  •  孤街浪徒
    2020-12-13 03:47

    Try below :

    DECLARE @myDateTime DATETIME
    SET @myDateTime = '2013-02-02'
    
    -- Convert to string now
    SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)
    

提交回复
热议问题