# How to convert decimal numbers to Hours and minutesRSS

## 2 replies

Last post Apr 04, 2014 04:00 PM by jesalynolson

• ### How to convert decimal numbers to Hours and minutes

Hi,

I am using SSRS 2005. I want to convert decimal numbers to Hours and minutes.

Say suppose, I am adding daily work hours and minutes and the total is 208.63.
Here 208 hrs and 63 minutes. How to convert this to 209 hrs 03 minutes in SSRS.
Any In-built function is there? or how to do using custom code?

Regards,
Bala

• Sam - MSFT

Star

10596 Points

1379 Posts

### Re: How to convert decimal numbers to Hours and minutes

Apr 02, 2014 10:03 PM|Sam - MSFT|LINK

Hi,

#### BalakrishnanShanmugham

I am using SSRS 2005. I want to convert decimal numbers to Hours and minutes.

Say suppose, I am adding daily work hours and minutes and the total is 208.63.
Here 208 hrs and 63 minutes. How to convert this to 209 hrs 03 minutes in SSRS.
Any In-built function is there? or how to do using custom code?

There is no build in function as such which can help you to achieve that. You have to write a function at the DB Query level to get the data in that format.

Refer to the following query. It will help you to split the above into Hours and Minutes.

```declare @workhours float = 208.63
declare @str varchar(10) = Convert(varchar,@workhours)
declare @index int =null
select @index=CHARINDEX('.',@str)

declare @hours int =Convert(int,Substring(@str,0,@index))
declare @minutes int= Convert(int,Substring(@str,@index+1,len(@str)))
select @hours as Hours, @minutes as Minutes```

OutPut:

```Hours |  Minutes
208   |  63```

You can modify it further as per your need.

Best Regards!

• jesalynolson

Member

150 Points

36 Posts

### Re: How to convert decimal numbers to Hours and minutes

As he said the easiest way is SQL but you will want convert your minutes by dividing them by 60 and taking the whole number and adding it to the hours.

```DECLARE @Hours DECIMAL(10,2)= '208.63'
DECLARE @Hour INT
DECLARE @Minutes INT
DECLARE @MinutesCalc DECIMAL(10,2)
DECLARE @HourCalc INT

SELECT @MinutesCalc = RIGHT(@Hours,LEN(@Hours)-CHARINDEX('.',CONVERT(VARCHAR,@Hours)))/60.00

SELECT @Hour = CONVERT(INT,LEFT(@Hours,CHARINDEX('.',CONVERT(VARCHAR,@Hours))-1)) + CONVERT(INT,LEFT(@MinutesCalc,CHARINDEX('.',CONVERT(VARCHAR,@MinutesCalc))-1))
SELECT @Minutes = RIGHT(@MinutesCalc,LEN(@MinutesCalc)-CHARINDEX('.',CONVERT(VARCHAR,@MinutesCalc)))

SELECT @Hour
SELECT @Minutes```