SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Convert Hours standing in the Number Format to Dec
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rafamarttins
Starting Member

Brazil
2 Posts

Posted - 02/27/2014 :  08:06:55  Show Profile  Reply with Quote
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)

Singapore
17596 Posts

Posted - 02/27/2014 :  08:14:43  Show Profile  Reply with Quote
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
Time is always against us

Go to Top of Page

rafamarttins
Starting Member

Brazil
2 Posts

Posted - 02/27/2014 :  08:25:39  Show Profile  Reply with Quote
I need to convert 8.48 to 8.8 (decimal).
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 02/27/2014 :  12:17:38  Show Profile  Reply with Quote
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.

Edited by - Lamprey on 02/27/2014 12:18:40
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000