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 2005 Forums
 Transact-SQL (2005)
 Datepart

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2009-09-25 : 15:44:33
I have one value in sql 1/1/1900 9:34:00 PM no i want to show only 9:34:00 PM in report.

what to do

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-25 : 15:56:39
Look at Cast and Convert in Books Online. That has a bunch of out-of-the-box conversion formats for datetime to varchar values.

You may need to apply some string manipulation to tweak the values to just the way you need them. Here is a format version without the seconds/milliseconds and 12 hour format:



select convert(varchar, dt, 100) [full] --straight convert to varchar
,right(convert(varchar, dt, 100),7) [right7] --just the time portion of the date
,stuff(right(convert(varchar, dt, 100),7), 6, 0, ' ') [with_space] --if you need a space before AM/PM

from (select convert(datetime, '1/1/1900 9:34:00 PM') as dt) d

output:
full right7 with_space
------------------------------ ------- ----------
Jan 1 1900 9:34PM 9:34PM 9:34 PM


Be One with the Optimizer
TG
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-25 : 15:58:53
Depending on the "reporting" application, many have date formatting capabilities. If so it is preferable to format them in the report (or front-end application)

Be One with the Optimizer
TG
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2009-09-25 : 16:02:33
thanks
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-09-25 : 22:58:49
Hi, see the below specified link

http://www.sql-server-helper.com/tips/date-formats.aspx
Go to Top of Page
   

- Advertisement -