Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Display time in 12 hour format

Author  Topic 

mrm23
Posting Yak Master

198 Posts

Posted - 2010-12-13 : 07:25:47
Hi All,

I need to display time in 12 hour format.
I got a solution for this as :

select Ltrim(right(convert(char(19),getdate(),100),7))

This gives time like 11:05AM , 12:08 PM etc.

I want to use these time values for a graph. so, i need only 24 values:

12 AM - 11PM

i.e : 12 AM , 1AM ,2AM,3AM..........11PM ----> total 24 values.

Can anyone help on this?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-13 : 07:33:09
dateadd(hh,datepart(hh,dte),dateadd(dd,datediff(dd,0,dte),0))

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2010-12-14 : 14:18:50
Why are you doing display formating in the database and not the front end? Let the reporting tool do this stuff, like it is supposed to.

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -