# Date declaration bug

**URL:** <https://forum.servoy.com/t/date-declaration-bug/19803>\
**Category:** Classic Servoy\
**Created:** [October 5, 2018, 7:22am UTC](https://forum.servoy.com/t/date-declaration-bug/19803 "2018-10-05T07:22:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![briese-it](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@briese-it](https://forum.servoy.com/u/briese-it)\
**Post date:** [October 5, 2018, 7:22am UTC](https://forum.servoy.com/t/date-declaration-bug/19803/1 "2018-10-05T07:22:49Z")

</div>

I created a form variable and want to set a specific month on the onShow event for that variable but the variable has still the original month. Changing a new date variable created on the onShow event is working fine.  
Is it a bug?

```auto
/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"A25E3416-1A34-4CC5-9C21-BBC05B9C434C",variableType:93}
 */
var dateMinus6Month = new Date();

/**
 * @param {Boolean} firstShow
 * @param {JSEvent} event
 * @override
 *
 * @properties={typeid:24,uuid:"C8A32A7E-EA94-488B-A2BA-1D17D0BDE7D3"}
 */
function onShowForm(firstShow, event) {
	_super.onShowForm(firstShow, event);

	/** @type {Date} */
	var testDate = new Date();
	testDate.setMonth(testDate.getMonth()-6);

	dateMinus6Month.setMonth(dateMinus6Month.getMonth()-6);

	application.output("dateMinus6Month: " + dateMinus6Month)
	application.output("testDate: " + testDate)
}

```

Result:  
dateMinus6Month: Fri Oct 05 2018 09:16:02 GMT+0200 (MESZ)  
testDate: Thu Apr 05 2018 09:16:02 GMT+0200 (MESZ)

---

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [October 6, 2018, 6:07pm UTC](https://forum.servoy.com/t/date-declaration-bug/19803/2 "2018-10-06T18:07:49Z")

</div>

Try initializing the date in the onShowForm() method.

```auto
/**
* @type {Date}
*
* @properties={typeid:35,uuid:"A25E3416-1A34-4CC5-9C21-BBC05B9C434C",variableType:93}
*/
var dateMinus6Month = null;

/**
* @param {Boolean} firstShow
* @param {JSEvent} event
* @override
*
* @properties={typeid:24,uuid:"C8A32A7E-EA94-488B-A2BA-1D17D0BDE7D3"}
*/
function onShowForm(firstShow, event)
{
   _super.onShowForm(firstShow, event);

   /** @type {Date} */

   var today = new Date();

   var testDate = today;

   dateMinus6Month = today;

   testDate.setMonth( testDate.getMonth() - 6 );

   dateMinus6Month.setMonth( dateMinus6Month.getMonth() - 6 );

   application.output( "dateMinus6Month: " + dateMinus6Month )

   application.output( "testDate: " + testDate )
}

```
