# Thread: How to convert decimal time value to hh:mm?

1. Registered User
Join Date
Sep 2009
Posts
3

## How to convert decimal time value to hh:mm?

I have a script which returns a decimal value to represent time. I need to convert the decimal time value to hh:mm (i.e: 90 minutes decimal value 1.5 should be represented as 1:30. Having trouble figuring this out. Attached is my current script.

Code:
```<script>
function Convert() {
var minutes = document.getElementById("sum").value;
var hours = minutes / 60;
document.getElementById('total').value = hours;
document.getElementById('sum').value = minutes;
var convert = function (sum) {
return Math.floor(sum/60) + ":" + (sum-Math.floor(sum/60)*60);
}

</script>```

2. Something like this ...
Code:
```<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title> Untitled </title>
<body>
<input id="HrMin" value="1.5"> Decimal Hours and Minutes <br>
<button
onclick="document.getElementById('HHMM').value=convertToHHMM(document.getElementById('HrMin').value)">
Convert to HH:MM</button>
Results <input id="HHMM" value="">

<script type="text/javascript">

function convertToHHMM(info) {
var hrs = parseInt(Number(info));
var min = Math.round((Number(info)-hrs) * 60);
return hrs+':'+min;
}
</script>

</body>
</html>```

3. Registered User
Join Date
Sep 2009
Posts
3
That works ..... Thank You

Originally Posted by JMRKER
Something like this ...
Code:
```<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title> Untitled </title>
<body>
<input id="HrMin" value="1.5"> Decimal Hours and Minutes <br>
<button
onclick="document.getElementById('HHMM').value=convertToHHMM(document.getElementById('HrMin').value)">
Convert to HH:MM</button>
Results <input id="HHMM" value="">

<script type="text/javascript">

function convertToHHMM(info) {
var hrs = parseInt(Number(info));
var min = Math.round((Number(info)-hrs) * 60);
return hrs+':'+min;
}
</script>

</body>
</html>```

4. You're most welcome.
Happy to help.
Good Luck!