Get Hours and Minutes (HH:MM) from date

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

    Here is syntax for showing hours and minutes for a field coming out of a SELECT statement. In this example, the SQL field is named "UpdatedOnAt" and is a DateTime. Tested with MS SQL 2014.

    SELECT Format(UpdatedOnAt ,'hh:mm') as UpdatedOnAt from MyTable
    

    I like the format that shows the day of the week as a 3-letter abbreviation, and includes the seconds:

    SELECT Format(UpdatedOnAt ,'ffffd hh:mm:ss') as UpdatedOnAt from MyTable
    

    The "as UpdatedOnAt" suffix is optional. It gives you a column heading equal tot he field you were selecting to begin with.

提交回复
热议问题