Format time as “24-hour Military Time”?

橙三吉。 提交于 2019-12-19 04:12:27

问题


I am updating some SQL Server 2000 code to SQL Server 2008R2, and there is function that looks a lot like this for converting the time into 24 hour format. What is a cooler/more clever way to do that in T-SQL?


回答1:


If all you want is just military time:

SELECT CONVERT(VARCHAR(8), GETDATE(), 108) AS MilitaryTime



回答2:


If you want time till second, then use this:

SELECT GETDATE() 'Today', 
       CONVERT(VARCHAR(8), GETDATE(), 108) 'hh:mi:ss'

IF you want time till millisecond, then use this:

SELECT GETDATE() 'Today',
    CONVERT(VARCHAR(12),GETDATE(),114) 'hh:mi:ss:mmm'

GETDATE() is used for current date you can pass any variable here.



来源:https://stackoverflow.com/questions/8074232/format-time-as-24-hour-military-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!