date variable value changes unexpected

In my function I have date variables (_date1, _date2) to set different payment dates by given terms (_pay1, _pay2).
The function is working so var so good, but when the first payment date (_date11) get its value the date variable (_date2) is changing to the value of _date11???
[attachment=2]date4.png[/attachment]

[attachment=1]date3.png[/attachment]
At the next step the value of _date2 changes to the value of _date1:
[attachment=0]date2.png[/attachment]
And when I execute the next step the values of _date1 and _date2 are the ‘Sat Mar 02 00:00:00 CET 2013’!?

The main problem for me is that the value of _date21 is always wrong.
I cannot understand how the variables (_date1 + _date2) can change their value?

Servoy 7.4.1

Be aware that date variables are objects. Thus if you call that functions with the same variable date for _date1 and _date2 means if you change _date1 than also _date2 changes because it’s the same object.

But _date1 and _date2 are two seperate parameter of the function!? They are two different variables, or?

Hi Thomas,

Dates are always passed as a reference to other functions.
Are doing perhaps doing something like this?

var _dDate = new Date();
myOtherMethod(_dDate, _dDate);


function myOtherMethod(_dDate1, _dDate2) {
    // both params point to the same original date object
}

if so you should create a new date object using the other like so:

var _dDate = new Date();
myOtherMethod(_dDate, new Date(_dDate));


function myOtherMethod(_dDate1, _dDate2) {
    //now you have unique date objects
}

Thank you Robert!
You are right and I changed my code like your example. Now it works as expected.