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 2000 Forums
 SQL Server Development (2000)
 converting integer mins to hrs and days

Author  Topic 

chris_wood99
Yak Posting Veteran

70 Posts

Posted - 2006-02-02 : 07:29:48
hi,

I have an application that gives all of its times in mins. I needed to convert this to mins, hrs, days(8hrs) to get some meaningful reports for the Users.

my programming skills are pants, even i can get the hrs by dividing by 60, but is there a function or something from this to give me the remainder so i can work out the mins?

can anyone help please.

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-02-02 : 08:06:18
You can use the modulo operator (%). I.e.

SELECT 150 % 60
-----------
30



Mark
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2006-02-02 : 08:09:43
something like this though not the most efficient way :


create function data(@mins int)
returns varchar(200)
as
begin
declare @hours int, @days int, @date varchar(200)
select @hours =@mins/60
if @hours>=8
select @days=@hours/8,@hours=(@hours%8)

select @mins=@hours%60
set @date = convert(varchar(10),isnull(@days,0))+' Days '+convert(varchar(10),isnull(@hours,0))+' Hours and '+convert(varchar(10),isnull(@mins,0))+' Minutes'
return @date

end

select dbo.data(8888)


Go to Top of Page
   

- Advertisement -