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...)
Printable View
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...)
Date calculations:
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.Code:<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>
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.
okie, Thanks a lot riis for the code and some explanation on it.
:D
may the light be with u :D