Filter dataset between date ranges

I have some code that was written for me to filter between two dates, but it doesn’t work how I want it too. Basically the filter is for temporary holiday sites and some can be open for up to four weeks at a time but when using .ge and .le if someone searches for a 1 week period during the 4 week opening dates of the site then the site does not show up in the filtered data.

This is a snippet of the code used for filtering the dates.


function filter() {
    let currentFilter = wixData.filter().not(wixData.filter().eq("status", "Withdrawn by DA"))
    if ($w('#from').value) {
        currentFilter = currentFilter.ge("startDate", $w('#from').value)
    }
    if ($w('#to').value) {
        currentFilter = currentFilter.le("finishDate", $w('#to').value)
    }

Your’e code is fine but then you have to run the filter:

$w('#dataset1').setFilter(currentFilter);

Thanks for your reply, that information is there. There is a lot of code that I didn’t post.

Thankfully the person that wrote the code changed it for me and it now works how I expected it to.


function filter ( ) {
let currentFilter = wixData . filter (). not ( wixData . filter (). eq ( “status” , “Withdrawn by DA” ))
if ( $w ( ‘#from’ ). value ) {
currentFilter = currentFilter . le ( “startDate” , $w ( ‘#from’ ). value )
}
if ( $w ( ‘#to’ ). value ) {
currentFilter = currentFilter . ge ( “finishDate” , $w ( ‘#to’ ). value )
}


Although I can see what has changed, It doesn’t make sense to me that .le and .ge have been transposed but it does seem to work so I can’t complain.

I am still struggling with this filter, I am in need of something that will filter during 2 dates rather than specifically equal to or greater than the first date and less than or equal to the end date.

This formula does not work if you want the search to pick up anything during those dates even if the start date is less than the search date.