Convert Time DataType into AM PM Format:

后端 未结 12 648
悲哀的现实
悲哀的现实 2020-12-23 16:02

I have one Table which has two fields such as \"StartTime\" and \"EndTime\". The DataType of the Two columns are Time.

So the Values of the Table looks like as follo

12条回答
  •  旧巷少年郎
    2020-12-23 16:50

    Using @Saikh's answer above, the 2nd option, you can add a space between the time itself and the AM or PM.

    REVERSE(LEFT(REVERSE(CONVERT(VARCHAR(20),CONVERT(TIME,myDateTime),100)),2) + ' ' + SUBSTRING(REVERSE(CONVERT(VARCHAR(20),CONVERT(TIME,myDateTime),100)),3,20)) AS [Time],
    

    Messy I know, but it's the solution I chose. Strange that the CONVERT() doesn't add that space automatically. SQL Server 2008 R2

提交回复
热议问题