time format in SQL Server

前端 未结 7 1743
心在旅途
心在旅途 2020-12-04 01:20

Does anyone know how can I format a select statement datetime value to only display time in SQL Server?

example:

Table cuatomer
id   name   datetime
         


        
7条回答
  •  天命终不由人
    2020-12-04 02:02

    You can use a combination of CONVERT, RIGHT and TRIM to get the desired result:

    SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7))
    

    The 100 you see in the function specifies the date format mon dd yyyy hh:miAM (or PM), and from there we just grab the right characters.

    You can see more about converting datetimes here.

提交回复
热议问题