By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,849 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,849 IT Pros & Developers. It's quick & easy.

Calculating difference between two dates using JS

P: 1
I saw that someone asked a similar question before, but it's not what I'm looking for.
I have two date fields (check in, check out) and "number of days" field.
I want the script to calculate automatically the difference.
For example: I have defaults dates, and I want the script to put the difference in "number of days" field. And if the user will change the date, the number of days will change automatically.

Nov 10 '06 #1
Share this Question
Share on Google+
1 Reply

P: 1
Have you tried this:

var numdays = Number(10);
var now = new Date();
var before = new Date();
before.setTime( now.getTime() - numdays * 24 * 60 * 60 * 1000);
Nov 12 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.