Warm tip: This article is reproduced from serverfault.com, please click

sql server-如何在 T-SQL 中将日期时间转换为字符串

(sql server - How to convert a datetime to string in T-SQL)

发布于 2013-02-22 17:24:34

我很惊讶不能在这里找到这个问题。

我有一个日期时间变量,我想将它转换为一个字符串,以便我可以将它附加到另一个字符串。我想要一种可以轻松转换回日期时间的格式。

我怎样才能做到这一点?

(我想要日期部分和时间部分。)

Questioner
cja
Viewed
22
John Woo 2013-02-23 01:25:38

以下查询将获取当前日期时间并转换为字符串。使用以下格式
yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar(25), getdate(), 120)