Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Difference

Status
Not open for further replies.

nalbiso

Programmer
Aug 31, 2000
71
US
Hi,

I am looking for a script to calculate the difference hours and minutes between two fields (TimeDepart and StartBackTime).

Any help would be greatly appreciated.

Thanks!
 
here's one way:

Code:
<html>
<head>
<title>hh mm diff</title>

<script name=&quot;javascript&quot;>
function diff(d1, d2) {
	d1 = new Date(d1);
	d2 = new Date(d2);
	diffS = (d2 - d1) / 1000;
	diffM = Math.floor(diffS / 60);
	remS = diffS % 60;
	return (diffM + &quot;:&quot; + remS);
}
</script>

<style type=&quot;text/css&quot;>
</style>

<meta name=&quot;author&quot; content=&quot;?&quot;>
<meta name=&quot;keywords&quot; content=&quot;?&quot;>
<meta name=&quot;description&quot; content=&quot;?&quot;>
</head>

<body onload=&quot;&quot;>
<form name=&quot;&quot; action=&quot;&quot; method=&quot;&quot;>
Enter two dates in this format:  MM/DD/YY HH:MM:SS
<p />
<input type=&quot;text&quot; name=&quot;t1&quot; value=&quot;&quot; />
<input type=&quot;text&quot; name=&quot;t2&quot; value=&quot;&quot; />
<input type=&quot;button&quot; name=&quot;&quot; value=&quot;diff();&quot; onclick=&quot;alert('mm:ss between date 1 & 2: ' + diff(this.form.t1.value,this.form.t2.value));&quot; />
</form>
</body>
</html>


========================================================= ======================================

if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top