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)
 converting a value to a time

Author  Topic 

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-12-02 : 10:05:28
Hi,

i have time values in a database which is entered as float for example 6.5, 6.0, 6.25

Now I want to convert these values to a hour:min format like 6.50 should become 6:30 and 6.25 should become 6:15

is there a way to do this or a sql function for this?

Thanks

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-12-02 : 10:24:23

There is no hour:min format in sql, but you can make those values look like times, but they will actually be strings
declare @hhmmin float
declare @hhmmin float
set @hhmmin = 6.1
SELECT convert(varchar(5),dateadd(mi,@hhmmin*60,0),108)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-12-02 : 11:09:57
Thanks jim! just what i was lokking for
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-03 : 03:44:19
You may need to read this too
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/11/15/time-calculation-on-numbers.aspx

Madhivanan

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

- Advertisement -