|
-
Nov 1st, 2002, 02:25 AM
#1
Thread Starter
Lively Member
(**resolved**)calculate days between two date given
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...)
Last edited by ZUWARI; Nov 6th, 2002 at 12:14 AM.
-
Nov 1st, 2002, 10:08 AM
#2
Fanatic Member
Date calculations:
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>
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.
-
Nov 6th, 2002, 12:13 AM
#3
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|