ZUWARI
Nov 1st, 2002, 01:25 AM
how should i code such code that can receive 2 date input from text box and output result (in days: date1- date2) in the 3 text box ( i'm talking about JavaScript here...)
riis
Nov 1st, 2002, 09:08 AM
Date calculations:
<html>
<body>
<script type="text/javascript">
var dateA = new Date();
var dateB = new Date(2000, 0, 1, 0, 0, 0);
var diff = parseInt((dateA - dateB)/86400000);
document.writeln(diff + "<br>");
document.writeln(dateA.getDate() + "-" + (dateA.getMonth() + 1) + "-" + dateA.getYear() + "<br>");
</script>
</body>
</html>
You're responsible yourself for parsing and validating the input of those textboxes. The code above shows how you can use the Date object in Javascript.
diff will hold the difference between both dates in whole days. (The subtraction itself returns the number of milliseconds.)
Btw new Date() will return the current date and time. When months are given numerically, keep in mind that it should be zero-based, so november will be 10, for instance.
ZUWARI
Nov 5th, 2002, 11:13 PM
okie, Thanks a lot riis for the code and some explanation on it.
:D
may the light be with u :D