How to convert a datetime to string in T-SQL

前端 未结 9 1363
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  Happy的楠姐
    2020-12-13 03:44

    There are many different ways to convert a datetime to a string. Here is one way:

    SELECT convert(varchar(25), getdate(), 121)  – yyyy-mm-dd hh:mm:ss.mmm
    

    See Demo

    Here is a website that has a list of all of the conversions:

    How to Format datetime & date in SQL Server

提交回复
热议问题