|
<script language=javascript>
<!--
function timeDiff(strTime1, strTime2)
{
var date1= new Date('1/1/03 ' + strTime1);
var date2= new Date('1/1/03 ' + strTime2);
var mins1= (date1.getHours() * 60) + date1.getMinutes();
var mins2= (date2.getHours() * 60) + date2.getMinutes();
var diff;
if ( mins1 <= (12*60) && mins2 >= (13*60) )
{
diff= (mins2 - (mins1 + 60)) / 60;
}
else
{
diff= (mins2 - mins1) / 60 - 1;
}
return UntoNdp(diff,2);
}
function UntoNdp(X, N)
{
var p = Number('1e'+N), S = new String(Math.round(X*p)/p)
if (S.indexOf('e') == -1 ) {
while ( (p = S.indexOf('.')) == -1 ) { S += '.' }
while ( S.length <= p+N ) { S += '0' } }
return S
}
//-->
</script>
<input type=text name="date1" size="15">
<input name="timein" type="text">
<input type=text name="date2" size="15">
<input name="timeout1" type="text">
<input type="text" size="10" name="txtTime3">
<input type="button" value="click to view the no. of hours spent" onclick="this.form.txtTime3.value=(timeDiff(this.form.timein.value,this.form.timeout1.value));">
my existing script shows the difference between two times,whenever the user clicks the button
it displays on the textbox the difference of the two given times.
My problem is the dates if the value of two date like
11/20/2003 5:48 PM
11/21/2003 2:00 AM
to get the difference of two times the two dates should also be considered and i am using
Function timeDiff.
pls. help!
thanks
|
|
|
|
|
|
|
|