how to calculate difference between two dates in percentage

Shilpi Sharma2
Tera Contributor

Hi all,

 

i want to calculate difference between two dates in percentage.

1 ACCEPTED SOLUTION

Omkar Mone
Mega Sage

Hi 

I have tried the below code in my Background script, let me know if this is what you want - 

 

var start = new Date(2015,06,01),//6 July 2015
end = new Date(2015,11,01),//1 Nov 2015
today = new Date();//todays date

gs.print("Start="+start);
gs.print("End="+end);
gs.print("Today="+today);


var timeBetweenStartAndEnd = (end - start); 
var timeBetweenStartAndToday = (today - start);


gs.print("Rounded: "+Math.round(timeBetweenStartAndToday / timeBetweenStartAndEnd * 100) + "%");

 

Hope this helps.

 

Regards,

Omkar Mone

View solution in original post

2 REPLIES 2

Omkar Mone
Mega Sage

Hi 

I have tried the below code in my Background script, let me know if this is what you want - 

 

var start = new Date(2015,06,01),//6 July 2015
end = new Date(2015,11,01),//1 Nov 2015
today = new Date();//todays date

gs.print("Start="+start);
gs.print("End="+end);
gs.print("Today="+today);


var timeBetweenStartAndEnd = (end - start); 
var timeBetweenStartAndToday = (today - start);


gs.print("Rounded: "+Math.round(timeBetweenStartAndToday / timeBetweenStartAndEnd * 100) + "%");

 

Hope this helps.

 

Regards,

Omkar Mone

Omkar Mone
Mega Sage

Hi Shilpi, 

 

If my response helped you, can you close this thread by hitting the correct answer so that it would be useful for others as well.

 

Regards,

Omkar Mone