 ## 5 replies

Last post Feb 07, 2019 04:53 PM by StrangerMike

• ### Decimal Convertion

Hello,

How can I convert decimal .17 to minutes 10.  Just showing the whole number 10 without a colon in SQL?

I have this:

CONVERT(CHAR(5), DATEADD(MINUTE, 60 * TotMTCHrs, 0), 108)

But it returns 00:10 instead of just 10.

Thanks!

Thanks
• ### Re: Decimal Convertion

If toMTCHrs is .17 then simply...

```DECLARE @min INT
SELECT @min =  60.0 * .17
SELECT @min```

• ### Re: Decimal Convertion

thanks mgebhard,

When I run that I get 10.2

Here is actual line it is being used in.

the result of this:

(TotMTCHrs equals .166667)

cast(case when TotMTCHrs < 0 then 24 + TotMTCHrs else TotMTCHrs end as decimal(8,2)) = .17

This:

cast(case when TotMTCHrs < 0 then 24 + TotMTCHrs else TotMTCHrs end as decimal(8,2)) * 60 PunchMinutes,

Is giving me 10.2

Thanks
• ### Re: Decimal Convertion

#### StrangerMike

Is giving me 10.2

if you are using Decimal data type then convert it to Int

```DECLARE @TotMTCHrs  decimal(8,2)
SET @TotMTCHrs  =  .166667
Select Cast(cast(case when @TotMTCHrs < 0 then 24 + @TotMTCHrs else @TotMTCHrs end as decimal(8,2)) * 60 as int ) PunchMinutes```

Thanks,
Aje
My Blog | Dotnet Funda
• ### Re: Decimal Convertion

#### StrangerMike

CONVERT(CHAR(5), DATEADD(MINUTE, 60 * TotMTCHrs, 0), 108)

But it returns 00:10 instead of just 10.

You could also extract the minutes like below

```DECLARE @TotMTCHrs  decimal(8,2)
SET @TotMTCHrs  =  .166667
SELECT LTRIM(DATEDIFF(MINUTE, 0, CONVERT(CHAR(5), DATEADD(MINUTE, 60 * @TotMTCHrs, 0), 108))) ```

Reference

Thanks,
Aje
My Blog | Dotnet Funda