# new Date() keeps reference to original

**URL:** <https://forum.servoy.com/t/new-date-keeps-reference-to-original/16699>\
**Category:** Classic Servoy\
**Created:** [October 31, 2012, 5:20pm UTC](https://forum.servoy.com/t/new-date-keeps-reference-to-original/16699 "2012-10-31T17:20:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgarfield](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jgarfield](https://forum.servoy.com/u/jgarfield)\
**Post date:** [October 31, 2012, 5:20pm UTC](https://forum.servoy.com/t/new-date-keeps-reference-to-original/16699/1 "2012-10-31T17:20:29Z")

</div>

There is some sort of strange behavior going on when you make a copy of a date that comes from either a JSDataset or from a JSRecord. [edit also from utils.dateFormat)]

It appears that the copied date is actually just a reference back to the original date, leading to some very unexpected results once you start manipulating the date.

This has not always been the case, but I’m not sure when it started.

```auto
var rTest = foundset.getRecord(1);
var dOriginal = rTest.mydate;
var dCopy = new Date(dOriginal);
dCopy.setDate(dCopy.getDate() +7); //dOriginal also changes!

```

You can get around the issue if you double wrap the copy operation (make a new Date of a new Date).

Servoy 5.2.15

[Support Case](https://support.servoy.com/browse/SVY-3324)

**Edit: Uploaded new sample solution. The problem also exists with dates coming out of utils.dateFormat**

[PersistantDateReference.servoy](https://forum.servoy.com/uploads/short-url/n8PsQzeEK6l6Ocq5Sb0liJBPmG0.servoy) (4.44 KB)

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [October 31, 2012, 7:07pm UTC](https://forum.servoy.com/t/new-date-keeps-reference-to-original/16699/2 "2012-10-31T19:07:39Z")

</div>

I have seen this also in 6.0.8.

I worked around it because I had’nt the time to figure out, what was happening!

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [November 6, 2012, 10:00pm UTC](https://forum.servoy.com/t/new-date-keeps-reference-to-original/16699/3 "2012-11-06T22:00:08Z")

</div>

This is because something that comes from servoy is a java data not a native javascript date.  
And rhino has a feature that if it is a java date it just wraps it so that you have that write through behavior  
to make a copy:

var dCopy = new Date(dOriginal.getTime())
