Format time as “24-hour Military Time”?

前端 未结 2 775
情话喂你
情话喂你 2021-01-07 01:21

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/

相关标签:
2条回答
  • 2021-01-07 01:41

    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.

    0 讨论(0)
  • 2021-01-07 01:59

    If all you want is just military time:

    SELECT CONVERT(VARCHAR(8), GETDATE(), 108) AS MilitaryTime
    0 讨论(0)
提交回复
热议问题