Display Date in specific Format [SOLVED]

I have a DatePicker on my page and I have added an onChange function to it so that whenever a new date is selected the text element below the DatePicker displays the date in a specific format.

 
export async function exDate_change(event, $w) {
 const originalDate = $w("#exDate").value;
 const newDate = originalDate.split(' ').splice(0, 4).join(' ');
    $w('#cutDate').value = String(newDate);
}

Tried to use this code but its not working

never mind

 
export async function exDate_change(event, $w) {
 const originalDate = String($w("#exDate").value);
 const newDate = originalDate.split(' ').splice(0, 4).join(' ');
    $w('#cutDate').value = newDate;
}