Filter Dataset by Year and Month

Hi! I want to set a filter selecting the year and month with a dropdown, I already have filter with dropdown, but doesn’t work with the date on the database.


export function dropdown1_change(event) {
 let yearDate = $w('#dropdown1').value;
 let monthDate = $w('#dropdown3').value;
 let searchDate = new Date(yearDate, monthDate)
    console.log(searchDate)
    $w("#dataset1").setFilter(wixData.filter().eq("fecha", searchDate));
}

Welcome to JS date-hell. Anyway, you should do the following:

  1. create a new date for the 1-st of the chosen month + YEAR
  2. create a new Date for the 1-st of the next month + YEAR
    3)instead of .eq, use .between (see docs). Between does a >=startdate and <enddate
    That should work.

So you cannot just create a month, you must specify 2 days.