Calculate in time format

Asked

Viewed 492 times

0

I need help creating a time calculation. I have a field:

Hora inicial <input id="inicial")>
Hora final <input id="final">
Total de horas <input id="resultado">

I can add integers(00), but how it looks in hours format(00:00) gives error the calculation.

I know very little Javascript, someone can give a force?

I tried that:

<script type="text/javascript"> function calcular(){
   var n1 = parseInt(document.getElementById('n1').value, 10);
   var n2 = parseInt(document.getElementById('n2').value, 10);
   document.getElementById('resultado').innerHTML = n1 - n2;   
} 
</script>

If I pass a value as follows: 14:00 to n1 16:00 to N2

It does not display the 2 that is the result.

I want to know how long between 2:00 and 4:00.

I need to know only the difference on the same day, will not pass 24 hours so I can not pass date and return time. as suggested.

  • 1

    It would be good to [Dit] your post and add more details like what you tried to do, what data you have and what result you want to get. Here are some links that can help you take advantage of the site: [Tour] | [Ask]

  • 1
  • What is the format accepted in "start time" and "end time"? Only whole or minutes as well as 14:35for example?

  • minutes too.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.