如何在 T-SQL 中将日期时间转换为字符串 [英] How to convert a datetime to string in T-SQL
本文介绍了如何在 T-SQL 中将日期时间转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很惊讶不能在这里找到这个问题.
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 string. I want it in a format that can be converted easily back to a date time.
我该怎么做?
(我想要日期部分和时间部分.)
(I want the date part and the time part.)
推荐答案
以下查询将获取当前日期时间并转换为字符串.使用以下格式 yyyy-mm-dd hh:mm:ss(24h)
The following query will get the current datetime and convert into string. with the following format yyyy-mm-dd hh:mm:ss(24h)
SELECT convert(varchar(25), getdate(), 120)
- SQLFiddle 演示
- SQL Server 日期格式
这篇关于如何在 T-SQL 中将日期时间转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文