I've been trying to calculate the percentage between two dates given the code from some questions here in StackOverflow but the code doesn't work correctly. This is the question: Get the percent of time elapsed between two javascript dates
var start = new Date(2015,6,1),
end = new Date(2015,12,1),
today = new Date();
alert(Math.round(( ( today - start ) / ( end - start ) ) * 100) + "%");
I want to calculate the progress from the 1rst of june to the 1rst of december and I get "-7"
Please help! Thanks
var start = new Date(2015,6,1),
end = new Date(2015,11,1),
today = new Date();
//use Math.abs to avoid sign
var q = Math.abs(today-start);
var d = Math.abs(end-start);
alert("Rounded: "+Math.round((q/d)*100) + "%");
alert("Fraction: "+((q/d)*100) + "%");
Also read Ray Toal answer 6 is july not jun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With