Javascript Date difference as milliseconds, minutes, hours, days, weeks, months, or years
Javascript November 13th, 2009I needed to figure out the difference between two dates in Javascript, so I wrote up this function. It takes into account the days in each month as well as leap years. It will calculate years, months, weeks, days, hours, minutes, seconds, and milliseconds, or any combination of those. For example, if you want months and hours, this’ll do ya.
Let me know if anyone finds a discrepancy in the calculations.
View source of the sample page above for usage. Samples include a date comparison and a date countown.
April 15th, 2010 at 12:45 pm
This is excellent! Thanks for sharing.
June 16th, 2010 at 2:40 am
hey im sorry to say ur code is working for feb31 also!
June 29th, 2010 at 10:57 pm
@Majid: Glad you like it
@devkimuar: Not sure I understand what you mean…