Using calling a Variable used inside an Export Function

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.

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();
	
	
}

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:

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.

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

Do you want to get difference in days, hours?