[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

display in time in a normal format

Posted on 2014-08-05
5
Medium Priority
?
176 Views
Last Modified: 2014-08-11
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
0
Comment
Question by:al4629740
5 Comments
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 40242549
SELECT CONVERT(VARCHAR(10), HourTimeFrom, 100) AS HourTimeFrom,
   CONVERT(VARCHAR(10), HourTimeTo, 100) AS HourTimeTo
FROM tblOrgHours
0
 
LVL 14

Expert Comment

by:Russell Fox
ID: 40242569
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
 

Author Comment

by:al4629740
ID: 40242585
Russell,

I tried that route and it still shows up in the funky numbers
0
 

Author Comment

by:al4629740
ID: 40242659
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
 
LVL 49

Accepted Solution

by:
PortletPaul earned 1500 total points
ID: 40242780
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question