display in time in a normal format

I am placing time values into my excel sheet in vb6

The time that I have in my DB looks like the following:  DataType Time(7)

HourTimeFrom      HourTimeTo
13:00:00.0000000      14:00:00.0000000
09:00:00.0000000      10:00:00.0000000
09:00:00.0000000      10:00:00.0000000

I am using the following query

SELECT r.RegID,h.HourTimeFrom,h.HourTimeTo from tblOrgHours

I would like the output to return a standard time format or 1:00 PM
al4629740Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
SELECT CONVERT(VARCHAR(10), HourTimeFrom, 100) AS HourTimeFrom,
   CONVERT(VARCHAR(10), HourTimeTo, 100) AS HourTimeTo
FROM tblOrgHours
0
Russell FoxDatabase DeveloperCommented:
Or in Excel format those columns with the "h:mm AM/PM" custom format. That might make it easier to perform calculations against those time values (instead of converting it into text).
0
al4629740Author Commented:
Russell,

I tried that route and it still shows up in the funky numbers
0
al4629740Author Commented:
Using this method
SELECT CONVERT(VARCHAR(10), HourTimeFrom, 100) AS HourTimeFrom,
   CONVERT(VARCHAR(10), HourTimeTo, 100) AS HourTimeTo
FROM tblOrgHours

Does it take up much more processing time?  If so, is there a better way to do this?  

Is there a DataType that addresses this issue?
0
PortletPaulfreelancerCommented:
working with the time data type:
|                T |   STYLE8 |          STYLE14 |          ISO8601 | STYLE100 |          STYLE109 |  FORMAT_TT |
|------------------|----------|------------------|------------------|----------|-------------------|------------|
| 01:32:47.8000000 | 01:32:47 | 01:32:47.8000000 | 01:32:47.8000000 |   1:32AM | 1:32:47.8000000AM | 1:32:47 AM |

select
      t
    , convert(varchar,t,8)            as style8
    , convert(varchar,t,14)           as style14
    , convert(varchar,t,126)          as ISO8601
    , convert(varchar,t,100)          as style100
    , convert(varchar,t,109)          as style109

    , format(getdate(),'H:mm:ss tt')  as format_tt -- sql server 2012+ only
    
from (
      select cast(getdate() as time) as t
     ) x

Open in new window

see: SQL Server Date Styles (formats) using CONVERT()

Does it take up much more processing time?
 "much more?" no, "some more?" yes

If so, is there a better way to do this?  
see above query or the article below, there are alternatives, but in essence "not really"

Is there a DataType that addresses this issue?  
datetime might be easier, but you get the date as well as the time - you may not want that
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.