# Using calling a Variable used inside an Export Function

**URL:** <https://forum.wixstudio.com/t/using-calling-a-variable-used-inside-an-export-function/42530>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 26, 2018, 6:39pm UTC](https://forum.wixstudio.com/t/using-calling-a-variable-used-inside-an-export-function/42530 "2018-03-26T18:39:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![usman-ibraheem](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/usman-ibraheem/32/2583_2.png) [@usman-ibraheem](https://forum.wixstudio.com/u/usman-ibraheem)\
**Post date:** [March 26, 2018, 6:39pm UTC](https://forum.wixstudio.com/t/using-calling-a-variable-used-inside-an-export-function/42530/1 "2018-03-26T18:39:42Z")

</div>

I have a Variable that i declared outside an Export function. i want to use the value captured with another variable or value. The problem is, its not working. How do i make this work please. Is it the variable i should use or the Function itself. and how do i call it in WIXCODE. Thank you.

```javascript
var date1 ;
console.log(date1);
    
export function datePicker1_change(event, $w) {
	//Sole Function is to Get Date chosen Eg: 19th for Start Date 
	
	let chosenDate = new Date($w("#datePicker1").value);
    	date1 = chosenDate.getDate();
	
	
}

```

---

<div class="post-metadata">

**Author:** ![giedrius-grazevicius](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giedrius-grazevicius/32/711_2.png) [@giedrius-grazevicius](https://forum.wixstudio.com/u/giedrius-grazevicius)\
**Post date:** [March 26, 2018, 10:26pm UTC](https://forum.wixstudio.com/t/using-calling-a-variable-used-inside-an-export-function/42530/2 "2018-03-26T22:26:22Z")

</div>

Hi Usman,

this should work as long as you don’t change the page. The console.log statement you have, however, will work on the load of the script, at that time no value is set. But you can try:

```javascript
export function datePicker1_change(event, $w) { 
    console.log(date1);
    let chosenDate = new Date($w("#datePicker1").value);     	
    date1 = chosenDate.getDate(); 
}

```

It will log the previous value after you change the value in date picker. Second change should start logging.

---

<div class="post-metadata">

**Author:** ![usman-ibraheem](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/usman-ibraheem/32/2583_2.png) [@usman-ibraheem](https://forum.wixstudio.com/u/usman-ibraheem)\
**Post date:** [March 27, 2018, 7:15pm UTC](https://forum.wixstudio.com/t/using-calling-a-variable-used-inside-an-export-function/42530/3 "2018-03-27T19:15:00Z")

</div>

Yes i know this would work , i’ve tried it already. i want to capture the value as a variable to use it with another value. Eg. date1 = 19; // this is the value.  
then, i’ll also get date2= 25;

var result = date1 - date2 = -6;  
result \* 5 = etc…

i hope you understand now what i’m trying to achieve. To use the function or variable to do MAths thanks

---

<div class="post-metadata">

**Author:** ![giedrius-grazevicius](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giedrius-grazevicius/32/711_2.png) [@giedrius-grazevicius](https://forum.wixstudio.com/u/giedrius-grazevicius)\
**Post date:** [March 28, 2018, 3:35am UTC](https://forum.wixstudio.com/t/using-calling-a-variable-used-inside-an-export-function/42530/4 "2018-03-28T03:35:57Z")

</div>

Do you want to get difference in days, hours?
