Repeater filter from past 30 days

Hi Everyone,

This is my first, but probably not my last post as I am learning six code in developing my website. I have a site that I have a data repeater on pulling from a database and id like to add a filter on a button click event that shows only data that the creation date was 30 days or newer from that day. Is this possible?

Thank you for your help in advance.

Use .setFilter()
https://www.wix.com/corvid/reference/wix-dataset/dataset/setfilter

and filter by:

.ge("_createdDate", new Date(Date.now() - 30 * 86400000))

P.S. this is for 24h * 30d from this moment. If you want to calculate to hour 00:00 of the 30th day you should use some of the JS Date() methods.

Thank you so much! That worked perfect!

Can you clarify how I could accomplish the same goal, except filtering for the next 30 days? I am a novice when it comes to coding and I took a look at .setFilter() and still am unsure how to implement this code. Thanks

Here is my code below
import wixData from ‘wix-data’ ;

// …

$w ( ‘#dataset1’ ). setFilter ( wixData . filter ()
. ge ( “Date” , new Date ( Date . now () + 30 * 86400000 ))
);

I was able to achieve the task with this code - Incase this may help anyone in need of performing the same task.

import wixData from ‘wix-data’ ;

$w . onReady ( function () {
//Get current date

$w ( “#dataset1” ). onReady ( () => { console . log ( “The dataset is ready” ); } );

let currentDate = new Date ();

//Get records with future dates compared to current date
$w ( “#dataset1” ). setFilter ( wixData . filter ()
. gt ( “date” , currentDate )

);