ISSUE:
When a date is assigned to a variable (say: A) and when the value of the variable is stored in another variable (say B), any changes made to variable A will alter the value in variable B.
SOLUTION:
The issue is that B is being set as a pointer to what A is pointing to.
var B= new Date(A);
When B=A;
Here, a new Date object is created, we are just pointing to the date object from two separate variables. There’s only one object, so naturally, any changes you make to it are apparent regardless of which variable you look through.
Use var B= New Date(A)