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

• 02-25-2013, 01:20 PM
jansson_17
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>```
• 02-25-2013, 08:54 PM
JMRKER
Something like this ...
Code:

```<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> Untitled </title> </head> <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"> // From: http://www.webdeveloper.com/forum/showthread.php?273645-How-to-convert-decimal-time-value-to-hh-mm&daysprune=30 function convertToHHMM(info) {   var hrs = parseInt(Number(info));   var min = Math.round((Number(info)-hrs) * 60);   return hrs+':'+min; } </script> </body> </html>```
• 02-26-2013, 06:56 AM
jansson_17
That works ..... Thank You

Quote:

Originally Posted by JMRKER
Something like this ...
Code:

```<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> Untitled </title> </head> <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"> // From: http://www.webdeveloper.com/forum/showthread.php?273645-How-to-convert-decimal-time-value-to-hh-mm&daysprune=30 function convertToHHMM(info) {   var hrs = parseInt(Number(info));   var min = Math.round((Number(info)-hrs) * 60);   return hrs+':'+min; } </script> </body> </html>```

• 02-26-2013, 11:21 AM
JMRKER
You're most welcome.
Happy to help.
Good Luck!
:)

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.07246 seconds
• Memory Usage 2,356KB
• Queries Executed 11 (?)
Template Usage (21):
• (3)bbcode_code_printable
• (1)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates