Looking for a way to filter data by date

Sorry, but am not a java coder but am trying to do functions based on the calendar date.

Have found various codes and snippets, but looking for a way to filter a dataset on a page using for a current date (month and day are important, not year).

Have found the onready and filtering code but need an easy way to convert for comparison purposes the only representations I have within my databases of dates. I store dates as text and numbers in fields as follows:

Date - a text field

Jul 23

MONTH - a number field

7

DAY a number field

23

for this example.


I have uploaded code onto the page of interest:

let today = new date();

$w(“#DAYSOFTHEYEAR”).setFilter( wixData.filter()
.eq(“Date”, today)
);
console.log(today);

But clearly the format returned from date() is not in a good form to compare what I store.

But am lost in trying to get an easy way to compare dates as strings or numbers or whatever.

Any suggestions for what surely must be a problem solved a million times before?

Thank you for any assistance on this.

P.S. Also, can’t figure out how to print things to the console for debugging. The console.log thing does not show anything.

The best advise I can give you is: just use the “date” data type to store dates. If you do not want to, store days as strings in YYYYMMDD-format and do NOT compare a string to dates (as you just did with the new Date()-syntax) in your query, because that creates a Date Object and comparing that to a string goes bonkers.

I’m having the same problem by my database field is a date/time field. The data currently has dates ranging from early 2019 to early 2020. When I compare it with the variable ‘today’ (set up the same way as the original poster), It returns no results. What I can see when I display ‘today’ on the console log looks completely different in format to what I can see in the actual data. I suspect I need to convert something but can see no guidance on this using google. I had considered the cop-out of converting my dates to text but can see that this is an issue also:

Sample of first item in database:


Code:

$w.onReady( function () {
let today = new Date();
console.log(today);
//console.log(nextyear);
let filter = wixData.filter();
$w(“#dataset1”).setFilter(
filter.ge(“event date”, today)
);
})

Result on console log:

“2019-11-29T11:55:58.530Z”

No actual data is returned for the 2 entries in 2020

How do I convert one or other date so they understand each other?

My locale is the UK but WIX is still formatting the dates in the database in US format, which is making it doubly confusing. The date in the screen shot is actually 8 May 2019 on entry