Get Hours and Minutes (HH:MM) from date

前端 未结 8 455
佛祖请我去吃肉
佛祖请我去吃肉 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:55

    Following code shows current hour and minutes in 'Hour:Minutes' column for us.

    SELECT  CONVERT(VARCHAR(5), GETDATE(), 108) + 
    (CASE WHEN DATEPART(HOUR, GETDATE()) > 12 THEN ' PM'
        ELSE ' AM'
    END) 'Hour:Minutes'
    

    or

    SELECT  Format(GETDATE(), 'hh:mm') + 
    (CASE WHEN DATEPART(HOUR, GETDATE()) > 12 THEN ' PM'
        ELSE ' AM'
    END) 'Hour:Minutes'
    

提交回复
热议问题