views:

24

answers:

1

Hi

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

Thanks in advance

+2  A: 

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.

marc_s
Ridiculous that there is no DATE_FORMAT equivalent... Alas!
JD
@JD: agree, it's not SQL Server's strong side - then again, SQL Server is about **storing** data - not really about nicely presenting it...
marc_s