如何在SQL Server中显示日期和时间 [英] How to display the date and time in sql server
本文介绍了如何在SQL Server中显示日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望sql查询以下面给出的格式显示时间和日期...
dd/mm/yyyy Time ....我想以12小时格式显示时间..pls给我SQL查询.....
example; 12/05/2011 11:55 AM
i want the sql query to display the time and date in the format given below...
dd/mm/yyyy Time....i want to display the time in 12 hrs format..pls give me sql query.....
example;12/05/2011 11:55 AM
推荐答案
尝试以下方法:
Try this:
SELECT CONVERT(VARCHAR(10), GETDATE(), 101) + ' ' +
SUBSTRING(CONVERT(VARCHAR(20), GETDATE(), 9), 13, 5) +
' ' +
SUBSTRING(CONVERT(VARCHAR(30), GETDATE(), 9), 25, 2)
我从此处获得了AM/PM解决方案 [
I got the AM/PM solution from here[^]
P.S. I used Google to find this. :)
您应该始终在Google上进行搜索.
搜索"SQL中的格式化日期"将其作为第一个链接返回:
http://www.sql-server-helper.com/tips/date-formats.aspx [^ ]
You should always search on google first.
The search "Formatting Dates in SQL" returned this one as the first link:
http://www.sql-server-helper.com/tips/date-formats.aspx[^]
这篇关于如何在SQL Server中显示日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文