Filter table by date

@jfercalderonwix

The dates need to go through some Javascript manipulation to be ready to return results that you would expect. You need to apply a condition that is going to return all possible datetimes for a given datetime field from midnight on the start date to midnight on the ending date. Let’s say you have two date picker elements, this code will filter the dataset. Of course, you will need to substitute your dataset and date field names in the setFilter statement.

export function FilterDatasetByDate(){
 let yearValue = $w('#datePicker1').value.getFullYear();
 let monthValue = $w('#datePicker1').value.getMonth();
 let dayValue = $w('#datePicker1').value.getDate();
 let date1 = new Date(yearValue,monthValue,dayValue,0,0,0);
 
 yearValue = $w('#datePicker2').value.getFullYear();
 monthValue = $w('#datePicker2').value.getMonth();
 dayValue = $w('#datePicker2').value.getDate();
 let date2 = new Date(yearValue,monthValue,dayValue,23,59,59);
 
  $w('#dataset1').setFilter(wixData.filter()
      .between("dateField", date1, date2)
    )
    .then(() => {
      console.log("Filter is set.");
    })
    .catch((err) => {
      console.log(err);
    });
}