I want to find difference between two Dates. For that I did subtract one Date object from another Date object. My code is as follows :
var d1 = new Date(); /
If you need to be fairly accurate I suggest using days as your unit. Years have a variable number of days so do months, so saying "1 month" or "1 year" can mean different #s of days.
var d1 = new Date(); //"now"
var d2 = new Date(2012,3,17); // before one year
var msPerDay = 1000*60*60*24;
document.write( ((d1 - d2) / msPerDay).toFixed(0) + " days ago");