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)
 time issues

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2007-12-12 : 10:28:04
hi,
I have the hour and minute in a table as int's.
how can I put them together to show the time..
I have tried this :

CASE WHEN [min] = 0 THEN convert(varchar,hour) + ':' + convert(varchar,[min]) + '0'
ELSE convert(varchar,hour) + ':' + convert(varchar,[min]) END as [time]

but hour 9 for example seems to come after hour 15 . .

this also seems like a messy way to do this..




khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-12 : 10:31:34
[code]right('0' + convert(varchar(2), [hour]), 2) + ':' + right('0' + convert(varchar(2), [minute]), 2) [/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-12-12 : 10:32:26
Since you are converting it to varchar, 9 comes after 1 (the 1 in 15).
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-12 : 10:32:41
SELECT CONVERT(VARCHAR(5), DATEADD(MINUTE, 60 * Hours + Minutes, '19000101'), 108)
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-12 : 10:33:56
or
SELECT CONVERT(varchar(5), DATEADD(hour, [hour], DATEADD(minute, [minute], 0)), 108)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2007-12-12 : 10:54:17
cheers guys, you are awesome !
Go to Top of Page
   

- Advertisement -