Get Hours and Minutes (HH:MM) from date

前端 未结 8 452
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-02 07:26

I want to get only hh:mm from date.

How I can get this?

I have tried this :

CONVERT(VARCHAR(8), getdate(), 108)
相关标签:
8条回答
  • 2021-02-02 07:59

    You can easily use Format() function instead of all the casting for sql 2012 and above only

    SELECT FORMAT(GETDATE(),'hh:mm')
    

    This is by far the best way to do the required conversion.

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

    You can cast datetime to time

    select CAST(GETDATE() as time)
    

    If you want a hh:mm format

    select cast(CAST(GETDATE() as time) as varchar(5))
    
    0 讨论(0)
提交回复
热议问题