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 2008 Forums
 Transact-SQL (2008)
 Convert Hours standing in the Number Format to Dec

Author  Topic 

rafamarttins
Starting Member

2 Posts

Posted - 2014-02-27 : 08:06:55
Hello Friends,

How do I conveter a field that is in hours in decimal format to number?

Ex: 8:48 = 8.48

Convert 8.48 to decimal 8.8

Could someone help me?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-27 : 08:14:43
what is the data type of the 8:48 time ?


declare @time time,
@decimal decimal(10,2)

select @time = '8:48',
@decimal = 8.48

select @time, datepart(hour, @time) + datepart(minute, @time) / 60.0

select @decimal, floor(@decimal) + (@decimal * 100 % 100 / 60.0)



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

Go to Top of Page

rafamarttins
Starting Member

2 Posts

Posted - 2014-02-27 : 08:25:39
I need to convert 8.48 to 8.8 (decimal).
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-02-27 : 12:17:38
Here is one way:
DECLARE @Foo DECIMAL(18,2) = 8.48
SELECT FLOOR(@Foo) + (((@Foo - FLOOR(@Foo)) * 100) / 60.0)


EDIT: Doh, I didn't realize that Khatn already solved the issue.
Go to Top of Page
   

- Advertisement -