arneweise77
Programmer
Hi!
I have this "tricky" problem regarding total time elapsed.
Im using a form with 2 textboxes: Start-time, End-time which the user fills in values in string format. Let´s say start-time= 23:25:45, and end-time= 02:26:46. Now I want to present total time elapsed as = 3:01:01 in a third textbox.
Im using ASP.NET, and have a java script function for this problem. I´ve tried many ways to separate the string into parts, and do get them the separated. But I dont get the correct total time elapsed.
Is there a function to use with this problem, or can anyone help me with this? I´ll show you my code aswell.
Thanx in advance. Arne
Here is the code:
<script language="javascript1.2" type="text/javascript">
function SetOperationTime()
{
if ((window.form.starttxt.value.length > 0)) && (window.form.stoptxt.value.length > 0))
{
var start = window.form.starttxt.value
var end = window.form.stoptxt.value
var startsplit = start.split(":"
var endsplit = end.split(":"
if ((endsplit[0]) < (startsplit[0]))
{
endsplit[0] = 24 - endsplit[0]
if ((endsplit[1] ) < (startsplit[1]))
{
endsplit[1] = 60 - endsplit[1]
endsplit[0] = endsplit[0] - 1
}
if (endsplit[2] < startsplit[2])
{
endsplit[2] = 60 - endsplit[2]
endsplit[1] = endsplit[1] - 1
}
}
var sum = ((endsplit[0] - startsplit[0]) +":"+ (endsplit[1] - startsplit[1]) +":"+ (endsplit[2] - startsplit[2]))
var sumsplit = sum.split(":"
var sum_count = 1
while ((sumsplit[sum_count] < 10) && (sum_count < 3))
{
sumsplit[sum_count] = "0" + sumsplit[sum_count]
sum_count +=1
}
window.form.operationtxt.value = sumsplit[0] +":"+ sumsplit[1] +":"+ sumsplit[2]
}
else
{
window.form.operationtxt.value = "0:00:00"
}
}
</script>
I have this "tricky" problem regarding total time elapsed.
Im using a form with 2 textboxes: Start-time, End-time which the user fills in values in string format. Let´s say start-time= 23:25:45, and end-time= 02:26:46. Now I want to present total time elapsed as = 3:01:01 in a third textbox.
Im using ASP.NET, and have a java script function for this problem. I´ve tried many ways to separate the string into parts, and do get them the separated. But I dont get the correct total time elapsed.
Is there a function to use with this problem, or can anyone help me with this? I´ll show you my code aswell.
Thanx in advance. Arne
Here is the code:
<script language="javascript1.2" type="text/javascript">
function SetOperationTime()
{
if ((window.form.starttxt.value.length > 0)) && (window.form.stoptxt.value.length > 0))
{
var start = window.form.starttxt.value
var end = window.form.stoptxt.value
var startsplit = start.split(":"
var endsplit = end.split(":"
if ((endsplit[0]) < (startsplit[0]))
{
endsplit[0] = 24 - endsplit[0]
if ((endsplit[1] ) < (startsplit[1]))
{
endsplit[1] = 60 - endsplit[1]
endsplit[0] = endsplit[0] - 1
}
if (endsplit[2] < startsplit[2])
{
endsplit[2] = 60 - endsplit[2]
endsplit[1] = endsplit[1] - 1
}
}
var sum = ((endsplit[0] - startsplit[0]) +":"+ (endsplit[1] - startsplit[1]) +":"+ (endsplit[2] - startsplit[2]))
var sumsplit = sum.split(":"
var sum_count = 1
while ((sumsplit[sum_count] < 10) && (sum_count < 3))
{
sumsplit[sum_count] = "0" + sumsplit[sum_count]
sum_count +=1
}
window.form.operationtxt.value = sumsplit[0] +":"+ sumsplit[1] +":"+ sumsplit[2]
}
else
{
window.form.operationtxt.value = "0:00:00"
}
}
</script>