tags:

views:

99

answers:

2

How to display a time HH:MM format?

Using SQL 2000

In my Database time column datatype is varchar

Example

Table1

Time

08:00:00
09:00:23
214:23:32

Here I want to take only 08:00, 09:00, 214:23

How to make a query for this condition?

+2  A: 

Whilst you could choose to turn the varchar into a datetime and format it there, assuming you do not want rounding, you could could shortcut the process. (Assuming the time format in the varchar is consistent)

select left('08:00:00',5)

Edit : Question altered, now I would use

select substring('243:00:00', 1, len('243:00:00') - 3)

and replace the value I used with the appropriate field

Cheap and cheerful.

Andrew
If Hours like 124:00:00, 4283:00:22 means, How it will work.
Gopal
That wasn't in the original question but i've altered the string work you have to do. working out the basic string manipulation isn't tough work.
Andrew
+1  A: 

I think Andrew was onto a correct solution, just didn't address all of the possibilities:

SELECT LEFT(Time, LEN(TIME)-3)

should trim off the last 3 characters.

Now, if you want to round up, that's another story....

Stuart Ainsworth
Quesiton got altered after solution posted :/
Andrew
@Andrew: question didn't get *altered*. Subject was changed to better correspond the body of the question.
SilentGhost
OP altered it an added 214:23:32 case to the list. You subsequently altered the OP subject for clarity. It is of no consequence now.
Andrew
See : http://stackoverflow.com/revisions/1524867/list for alterations.
Andrew
@Andrew Sorry about that; didn't mean to swoop in on you.
Stuart Ainsworth
Not a problem, no offence intended or taken. :)
Andrew