467,915 Members | 1,290 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Displaying time from Datetime datatype

Hi every one,
I am new to sql server2005,I have datetime column
in my database ..I need to display only time part of the datetime .I
need to display in AM/PM format ..datetime is stored in this format mm/
dd/yyyy hh:mm:ss AM/PM .I need to display in this format hh:mm:ss AM/
PM ,How can i do that?? I searched for this on net but i got 24hour
format .
i tried this on my own ,but no hope!

Thanks in advance,
Oct 31 '08 #1
  • viewed: 3203
Share:
2 Replies
The DATETIME data type does not have format but it is rather stored as
binary value. Formatting is normally best done on the client side.

In T-SQL you can use the CONVERT function with style 109 and a bunch of
string manipulations to get the time formatted as string:

SELECT RIGHT('0' +
LTRIM(STUFF(RIGHT(
CONVERT(CHAR(26), CURRENT_TIMESTAMP, 109)
, 14),
9, 4, ' ')),
11);

--
Plamen Ratchev
http://www.SQLStudio.com
Oct 31 '08 #2
On Oct 31, 10:39*am, Plamen Ratchev <Pla...@SQLStudio.comwrote:
The DATETIME data type does not have format but it is rather stored as
binary value. Formatting is normally best done on the client side.

In T-SQL you can use the CONVERT function with style 109 and a bunch of
string manipulations to get the time formatted as string:

SELECT RIGHT('0' +
* * * * LTRIM(STUFF(RIGHT(
* * * * CONVERT(CHAR(26), CURRENT_TIMESTAMP, 109)
* * * * * * * * * * * , 14),
* * * * * * * * * * 9, 4, ' ')),
* * * * * * * 11);

--
Plamen Ratchevhttp://www.SQLStudio.com
Plamen Ratchev..
Thanks a lot for your help
Oct 31 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Larry Bertolini | last post: by
6 posts views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.