开发者

How to see this format hh:mm from hh:mm:ss in SQL Server 2008 query?

开发者 https://www.devze.com 2022-12-23 21:07 出处:网络
How to see this format hh:mm from hh:mm:ss in SQL开发者_Go百科 Server 2008 query ?There\'s no direct, built-in functionality for this.

How to see this format hh:mm from hh:mm:ss in SQL开发者_Go百科 Server 2008 query ?


There's no direct, built-in functionality for this.

Assuming you have a DATETIME or TIME column in SQL Server, you need to hack it like this:

SELECT
   SUBSTRING(CONVERT(VARCHAR(20), YourDateTimeColumn, 108), 1, 5)

The CONVERT statement with style = 108 will convert your date to hh:mm:ss and then you just chop off the last three characters.

Things like this really shouldn't be done in the database - that's purely presentation logic, and it belongs in the UI app.

0

精彩评论

暂无评论...
验证码 换一张
取 消