Reputation: 89
How can I display data type TIME in SQL as 09:00 or 09:00AM instead of 09:00:00.000000
For instance, I have a column start_time
and its type is TIME
When I insert data in it, INSERT INTO Time(start_time) VALUES('09:00:00')
It displays it as: 09:00:00.0000000
Upvotes: 2
Views: 501
Reputation: 2922
You need to format dates as per your requirement.
have a look at
http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx
or
http://www.w3schools.com/sql/func_convert.asp
sample
SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 101) AS [MM/DD/YYYY]
SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 103) AS [DD/MM/YYYY]
..........
Upvotes: 2
Reputation: 48522
You need to take a look at the Format function in T-SQL. This will allow you to format date and time values (and another values) any way you want to. The link I provided is for SQL 2014. Format was added in version 2012. You have your question tagged as 2008, so I'm not sure this answer will apply to you. If not, take a look at Cast and/or Convert here.
By the way, you may not know this but how you enter a date/time value into SQL Server has no relationship to how it is displayed. And, generally, the displaying of date and time values is done in some UI tier of an app, and not at the SQL Sever level, even though T-SQL provides methods for formatting dates and times.
Upvotes: 1