467,174 Members | 1,321 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,174 developers. It's quick & easy.

Calculating difference between two dates using JS

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
  • viewed: 4435
1 Reply
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.

Similar topics

4 posts views Thread by Hans Gruber | last post: by
10 posts views Thread by riki | last post: by
4 posts views Thread by iamonthisboat@gmail.com | last post: by
5 posts views Thread by Julius | last post: by
6 posts views Thread by krishnakant Mane | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.