# date variable value changes unexpected

**URL:** <https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132>\
**Category:** Classic Servoy\
**Created:** [August 22, 2014, 10:19am UTC](https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132 "2014-08-22T10:19:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [August 22, 2014, 10:19am UTC](https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132/1 "2014-08-22T10:19:47Z")

</div>

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

 ![date2.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/6/629290eb6fc3fcfb6f918d83d143c878216e39bd.png)

 ![date3.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/4/4e10d042a5504351ee52786317a6f009bdce0883.png)

 ![date4.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/4/48470db6e0697af03476acd3299cf35372ffd14f.png)

---

<div class="post-metadata">

**Author:** ![boonstrj](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@boonstrj](https://forum.servoy.com/u/boonstrj)\
**Post date:** [August 22, 2014, 10:34am UTC](https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132/2 "2014-08-22T10:34:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [August 22, 2014, 11:11am UTC](https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132/3 "2014-08-22T11:11:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 22, 2014, 11:30am UTC](https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132/4 "2014-08-22T11:30:55Z")

</div>

Hi Thomas,

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

```auto
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:

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

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

```

---

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [August 22, 2014, 12:16pm UTC](https://forum.servoy.com/t/date-variable-value-changes-unexpected/18132/5 "2014-08-22T12:16:50Z")

</div>

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