Get Hours and Minutes (HH:MM) from date

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

    The following works on 2008R2+ to produce 'HH:MM':

    select
    case
    when len(replace(replace(replace(right(cast(getdate() as varchar),7),'AM',''),'PM',''),' ','')) = 4
    then '0'+ replace(replace(replace(right(cast(getdate() as varchar),7),'AM',''),'PM',''),' ','')
    else replace(replace(replace(right(cast(getdate() as varchar),7),'AM',''),'PM',''),' ','') end as [Time]
    

提交回复
热议问题