Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help formating the Time from a smalldatetime field. 1

Status
Not open for further replies.

elmorro

Programmer
Jun 23, 2005
133
US
Hi all,
I have written a query that returns the StartTime field, but it returns it with the date attached to it:
1900-01-01 06:30:00.000

How can I format the field so that it only returns the time:
06:03 ?


Thanks is advance,
elmorro :)

 
Select Convert(VarChar(20), [!]YourDateTimeColumn[/!], 108)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks gmmastros. That helped alot, but I am still getting the time like this:
06:03:00
Is there any way to drop the trailing zeros and have it look like this:
06:03


elmorro :)
 
Select [!]Left([/!]Convert(VarChar(20), YourDateTimeColumn, 108) [!], 5[/!])


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Try this.

select convert(CHAR(5), getdate(), 108)

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
[lol]
Paul, I thought of that about 10 nanoseconds after clicking the submit button.

elmorro, use Paul's version instead. It is slightly better.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
[tongue]

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top