cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

JS Code

AP_9587236
17-Peridot

JS Code

I am storing same date in three variables. And subtracting days in one variable. But all variables value getting changed. Can someone pls explain why this is happening? 

This is the code: Input & Output Datatype is datetime:

var d1 = DateInp;
var d2 = DateInp;
var d3 = DateInp;
for (var sol=1;sol<=7;sol++){
d1.setDate(d1.getDate()-1);
}
var result = d3;

 

 

AP_9587236_0-1647866500076.png

AP_9587236_1-1647866530387.pngAP_9587236_2-1647866557803.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

 

This happens because your three date variables are actually all references pointing to the same object. You'd need to clone the input date to get separate references for each of your variables, e.g.:

var d1 = new Date(DateInp.getTime());

View solution in original post

1 REPLY 1

Hello,

 

This happens because your three date variables are actually all references pointing to the same object. You'd need to clone the input date to get separate references for each of your variables, e.g.:

var d1 = new Date(DateInp.getTime());
Top Tags