View Full Version : JavaScript Dates, minus (w/formatting)/difference

03-15-2012, 11:28 PM
Hi so because the jquery range slider has no date range ability and because the only date range plugin for jquery UI sliders is very bloated and fails to work on modern ipad / new touch event methods... I'm writing my own today..

Can some one better exmplain to me how to do:
"theCurrentDate (05/12/2012) - anOlderDate (05/12/1990) = difference of how many days is?"


"theCurrentDate (05/12/2012) - 200 = but resulting in date formatted version, not some 9394829398 number"?


03-15-2012, 11:53 PM
Dx = new Date("may 5,2012");
Dy = new Date("may 5,1990");
alert((Dx - Dy) / 86400000);
alert(new Date(Dx-(200*86400000)))
document.write(new Date(Dx-(200*86400000)));

03-16-2012, 12:39 AM
Thank you so much DaveyErwin!

One last question, is there a way to have the output of "new Date(Dx-(200*86400000))" be in this format, "18/10/2011" vs "Tue Oct 18 2011 00:00:00 GMT-0700 (Pacific Daylight Time)"?

03-16-2012, 03:29 AM
Each part of the date is available as date methods

getDate() returns the day of the month
getMonth() returns one less than the month number
getFullYear() returns the year


dR = new Date(Dx-(200*86400000));

If you want to add all of the extra functionality for adding and subtracting dates and being able to easily select the final format using codes similar to the PHP format command then take a look at http://javascriptexample.net/dollarD.php