Last month filter button

Hello everyone,
How do I create a button that filters a dataset to show only items from the last month.

Thank you.

Eny help please

You can do something like this:

import wixData from 'wix-data';

$w("#myButton").onClick( (event) => {
    let first = < first day of last month >;
    let last = < last day of last month >;

    $w("#myDataset").setFilter( wixData.filter()
        .ge("date-field", first)
        .le("date-field", last)
    .then( () => {
        console.log("Dataset is now filtered");
    } )
    .catch( (err) => {
    } );
} );

This should get you going in the right direction.

1 Like

will it work with the week and the year in the same way?

@oussamaismaili7 You just need to set first and last variables to the correct dates.

1 Like

Thank you so much @yisrael-wix

1 Like

Do you know a way to get last year’s date based on today’s current date.

let yearValue = (localDate.getFullYear() - 1 ) ;

@oussamaismaili7 I did a search for javascript get date year ago and I got lots of results. One good one is: How to determine one year from now in Javascript

Good luck.