How can I put a filter or restrict a dynamic page so that only information from up to 7 days from today appears.

How can I put a filter or restrict a dynamic page so that only information appears up to 7 days from today. The database has a start date field. and I want all the information from the table to be displayed in the repeater of the dynamic page but the information that is more than 8 days old does not appear.

Code Velo

I guess you’re doing this with a dataset rather than via code. If so, you’re probably looking for something like this:

import wixData from "wix-data"

$w.onReady(function () {
    let date = new Date();
    date.setDate(date.getDate() - 7);

    $w("#myDataset").setFilter(wixData.filter()
        .ge("startDate", date)
    );
});

You’ll need to update some of it to reflect your current setup

Good day

Yes, that’s right, I’m doing it with a data set.

Collection ID: publicationVeh
Dataset ID: #dynamicDataset

Should I add a date field to my collection?
Can you use the “creation date” field provided by the system in the collection?


image

How would the code look like?

Thanks for your help

Yep, it’d look something like:

import wixData from "wix-data"

$w.onReady(function () {
    let date = new Date();
    date.setDate(date.getDate() - 7);

    $w("#dynamicDataset").setFilter(wixData.filter()
        .ge("_createdDate", date)
    );
});