How To Get A Date in the Past for a Query

site: cosworthvega.com
page: locate-update-member

I have a custom membership database and need to run a report for members that have expired withing the last 90 days in order to send them a reminder.

Here is the code block:

let Today = new Date(); // Current Date
let numberOfDays = 365;
let expDate = Today.subtract(‘month’,3)
let displayDate = String(expDate);
console.log("Using date for Expired query: ", displayDate)

// EXPIRED RUN…
$w(wixData.filter()
.contains(‘mem_status’, $w(‘#statusValue’).value)
.eq(‘region’, $w(‘#regionValue’).value)
.gt(‘Expiry’, expDate)
);
}

GETTING RUNTIME ERROR IN JAVA CONSOLE:

TypeError: Today.subtract is not a function

I got this from a Google search on using dates in javascript.

@cwvega76 Subtract was probably a custom function that you didn’t include from the thread that you were looking at.

Here’s a way that you can reliably get ninety days back:

let  Today = new Date(); // Current Date
// Get time value for current date.
let TodayTime = Today.getTime();
//86400000 milliseconds in a day
let NinetyDaysAgo = TodayTime - (90 * 86400000);
let expDate = new Date(NinetyDaysAgo);
let displayDate = expDate.toString();
console.log("Expired query date: " + displayDate);

$w("#dataset1").setFilter( wixData.filter()
    .contains('mem_status', $w('#statusValue').value) 
    .eq('region', $w('#regionValue').value) 
    .gt('Expiry', expDate)
);

Thanks Much. I REALLY APPRECIATE it!