SQL sql日期时间格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5884781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql datetime format
提问by user517406
I am trying to convert a date into this format YYYY-MM-DD hh:mm:ss eg. 2007-01-05 23:00:00. But my SQL leaves the string unchanged, can somebody tell me what I am doing wrong?
我正在尝试将日期转换为这种格式 YYYY-MM-DD hh:mm:ss 例如。2007-01-05 23:00:00。但是我的 SQL 保持字符串不变,有人可以告诉我我做错了什么吗?
select convert(varchar,'23/02/2008 00:00:00',120)
回答by Nik
Try SELECT CONVERT(DATETIME, '23/02/2008 00:00:00')
. All you're doing is converting a string into a string, which won't change anything.
试试SELECT CONVERT(DATETIME, '23/02/2008 00:00:00')
。您所做的只是将字符串转换为字符串,这不会改变任何内容。
回答by Brian Driscoll
your data type needs to be DATETIME, eg:
您的数据类型需要是 DATETIME,例如:
select convert(DATETIME, '23/02/2008 00:00:00', 120)
select convert(DATETIME, '23/02/2008 00:00:00', 120)
回答by Floopy-Doo
try this. Works for Transact-SQL.
尝试这个。适用于 Transact-SQL。
select convert(datetime,'23/02/2008 00:00:00')
I hope it helps
我希望它有帮助
回答by gen
maybe you're looking to do this:
也许你想这样做:
CONVERT(varchar,'23/02/2008 00:00:00',100) 'yyyy-mm-dd hh:mm:ss'
回答by Ravi Sharma
select format(getdate(),'dd-MM-yyyy hh:mm tt')
选择格式(getdate(),'dd-MM-yyyy hh:mm tt')
回答by Ritesh Mengji
Following is the syntax to achieve what you are looking for
以下是实现您正在寻找的语法
SELECT CONVERT(VARCHAR(19), GETDATE(), 120)
选择转换(VARCHAR(19),GETDATE(),120)
To know more about the date formats see the link http://www.sql-server-helper.com/tips/date-formats.aspx
要了解有关日期格式的更多信息,请参阅链接 http://www.sql-server-helper.com/tips/date-formats.aspx