Click here to Skip to main content
15,887,961 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I need solution for calculating time difference between two give times in HTML. I have a HTML page with three text box and one button but unable to calculate time difference.

HTML
<html>
<head>

<script type = "text/javascript">

function difference()
{
	
}

</script>
</head>
<body>

From input type =  "text" size = "10" maxlength = "5" id = "startTime"><br>
To<input type =  "text"  size = "10" maxlength = "5" id = "endTime"><br><br><br>

<input type = "button" value= "Get Time Difference"  önclick = "difference()"><br><br>

<tr>
<td align="left">Calculated Time Difference    <input type="text" id="diff" readonly 

size="10">

</td>
</tr>

</body>
</html>


I don't have any idea what logic to use in function so please help me.

Thanks and Regards,
Ravindra Bisht
Posted
Updated 29-Mar-13 2:17am
v4

HTML doesn't have the functionality for this, you'll need to use a scripting language, such as PHP, Java Script, ASP.NET, etc.
 
Share this answer
 
You need to use this javascript to calculate time difference
http://psoug.org/snippet/Javascript-Calculate-time-difference-between-two-dates_116.htm[^]
 
Share this answer
 
Convert to date type and use method getTime() (milliseconds).
See example for days.

C#
var a = new Date(2009, 2, 31, 0, 0, 0, 0);
var b = new Date(2009, 2, 1, 0, 0, 0, 0);
alert((b.getTime() - a.getTime()) / (1000*60*60*24));
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900