Reset counter in database

I have a function button to let members to hits every day and set the limit to 10 times per day. But can I reset the counter automatically to “0” every day in my dataset and no need to click any button. Is it possible ?

export function Button_click() {
wixData.query(‘test’)
.find()
.then((result)=>{
let answersitem = result.items[0];
let id = answersitem._title;
answersitem.counter++; // increment counter field by 1
wixData.update(“test”, answersitem)
.then(()=>{
$w(“#dataset1”).refresh();
if (answersitem.counter >= 10) {
$w(‘#Button’).hide();
$w(‘#textMessage’).show();
}
});
});
}

In addition to the counter field, keep a date field for last date accessed. Then each time the user accesses the site, you can check the counter together with the date to see if it needs to be reset or not.

Hi Yisreal,
Thank you for your advise. Could you advise some code for date comparison ? if i want to check last date accessed is not equal today.

Wix code is it have some date comparison function like
Date.before(), Date.after() and Date.equals()

You can use standard Javascript Date functions in Wix Code, or you can add conditions to the database query. For example, use .le() to check if a data is less than or equal to the date that’s in the database. You can also use .lt(), .gt(), ge(), and others.

Thank a lot Yisrael. Finally, I use getDate() to solve my problem.