I want to filter my articles based on their months. There is the getMonth () method, how can I apply it the best?
Here my Try-Code:
wixData.query("myDatabase")
.eq("date".getMonth(), 1) // is not working
....
...
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
Another solution, this will obtain all the objects in the month of September
const monthMin = new Date('September 01, 2020'); const monthMax = new Date('October 01, 2020');
return wixData.query("MyCollection") .descending("number") //optional .ge("_dateCreated", monthMin) //greater or equal than... .lt("_dateCreated", monthMax) //less than... .find() .then((results) => {
Well I found a solution... it's not the best I think, but It works.
wixData.query("myDatabse") .ge("date", new Date()) // filter all old Dates out .find() .then((results) => { let filterItems = []; for (var i = 0; i < results.length; i++) { const item = results.items[i]; for (var j = 0; j < dateMonth.length; j++) { if (item.datum.getMonth() === Number(dateMonth[j])) { //dateMonth is an Stringarray of numbers between 1 to 12 filterItems.push(item._id.toString()); } } } // then setFilter with filterItems });
For any other or better solution please show it.
Cheers
Benjamin
Have a look at data sort as this can be added to your data query so that you can list your results as ascending or descending etc.
https://www.wix.com/corvid/reference/wix-data.WixDataSort.html