Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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;
Solved! Go to Solution.
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());
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());