Sunday, April 10, 2016

Finding difference between two dates in JS

"Finding difference between two dates" is not a new topic in JavaScript world, however with this post, i wish to go one step ahead by providing this ability as an extension of Date object itself and in a configurable manner.
In this code we extend Date object prototype with a new method named "difference". This method take another date (Created using "new Date()") and "unit" for comparison result i.e in what units do you want to know the difference e.g "seconds","minutes","hours","days" or "months"