tags:

views:

45

answers:

3

Possible Duplicates:
Calculating the difference between two dates
What’s the best way to calculate date difference in Javascript

How can I find difference between two dates in JavaScript?

+1  A: 
 return date1 - date2;
 // returns the number of microseconds between the two `Date`s.
KennyTM
@OP: Yes, really, it's *that* easy. :-) The result is a number, in milliseconds. You have to be careful with historical dates, though, Javascript's Date object doesn't handle the Gregorian change in 1582. For contemporary dates, though, it's fine.
T.J. Crowder
A: 

http://www.javascriptkit.com/javatutors/datedifference.shtml

vdk
No link-only answers, please. SO should stand on its own; external links can disappear, get renamed, etc.
T.J. Crowder
A: 

Do you mean something like this?

http://www.mcfedries.com/JavaScript/DaysBetween.asp

saturation
No link-only answers, please. SO should stand on its own; external links can disappear, get renamed, etc.
T.J. Crowder
aa ok, my bad. I will post the main idea from the link
saturation
but something like this: `<script language="JavaScript" type="text/javascript"><!--function days_between(date1, date2) { // The number of milliseconds in one day var ONE_DAY = 1000 * 60 * 60 * 24 // Convert both dates to milliseconds var date1_ms = date1.getTime() var date2_ms = date2.getTime() // Calculate the difference in milliseconds var difference_ms = Math.abs(date1_ms - date2_ms) // Convert back to days and return return Math.round(difference_ms/ONE_DAY)}//--></script>`
saturation