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
 General SQL Server Forums
 New to SQL Server Programming
 time converts

Author  Topic 

jjmoss1234
Starting Member

11 Posts

Posted - 2011-02-16 : 11:31:24
Hi There
I have 2 colums in a table (table_1) which show hours and minutes
so column 1 may show 23 and column 2 may show 7

how can I convert this to get a result of 23:07 as in a time element?

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-16 : 11:42:31
declare @col1 int, @col2 int
select @col1=23, @col2=7
select convert(char(12),DATEADD(hour, @col1,dateadd(minute,@col2,0)),108)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jjmoss1234
Starting Member

11 Posts

Posted - 2011-02-16 : 12:03:45
Thankyou very much Madhivanan

Much appreciated!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-16 : 12:04:13
quote:
Originally posted by jjmoss1234

Thankyou very much Madhivanan

Much appreciated!


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jjmoss1234
Starting Member

11 Posts

Posted - 2011-02-16 : 12:08:52
How do I get a whole table of different hrs and mins to convert?
Not just 23 and 7?
I.e. what do I set the variables as?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-02-16 : 16:20:03
select convert(char(8), DATEADD(hour, col1, dateadd(minute, col2, 0)), 108) from table1


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -