Filter column image based on today's date

@tony-brunsman I got it to work! There seemed to be a problem with the ‘current’ field, I deleted it and added a new one called ‘active’ and it worked straight away. Thank you for all your help! I’ve learned a lot and am excited to start a HTML and Javascript course in my University soon. Thank you!

@gavincoll That is odd. I’m wondering if the field key for the ‘current’ field was actually ‘Current’? In any event, I’m glad that you have it working!

@tony-brunsman Very weird. I have run into a slight issue. I added a field for tomorrow’s image of the day - 25th January - however, even though that date is in the future, the second gallery I have on the home page and another on a different page that shows all previous and the current photos still displays the future image as the code seems to change the ‘future’ and ‘active’ fields to false, as it should only do for dates in the past.

wixData.query('rigoftheday')
.lt('date', dateValue1)
.or(
wixData.query('rigoftheday')
.gt('date', dateValue2)
)
.find()
.then(results => {
console.log(results);
let updateArray = [];
// Loop through results of those that are true
// and out-of-date, change the value to false
// and then add the item to the updateArray.
for (var i = 0; i < results.items.length; i++) {
let thisItem = results.items[i];
if (thisItem.active) {
thisItem.active = false;
updateArray.push(thisItem);
if (thisItem.future){
thisItem.future = false;
updateArray.push(thisItem);
}
}



}
// Now, update the collection records with this array of
wixData.bulkUpdate('rigoftheday', updateArray)
.then((bulkresults) => {
// this will return an array showing the IDs of the
// updated records.
console.log(bulkresults);
})
.catch((err) => {
console.log(err);
});

@tony-brunsman On the above, I realised as it’s due to the .lt and .gt selectors. I tried to create a second set of code underneath that used .gt(‘date’, localDate) and also .gt(‘date’, dateValue1, dateValue2) but neither seem to be working

My desired states are:
If date is before today → active = false, future = false
if today → active = true, future = false
if future → active = false, future = true

@gavincoll I didn’t know what you wanted to do with future dates when I wrote that.

Greater than (gt) only needs the field and one value as arguments. Try .gt(‘date’,dateValue2)

@tony-brunsman thank you! I’ll try this. For current days, is it best to do .eq(‘date’, localDate) or should I do greater than dateValue1 and less than dateValue2

@gavincoll For current days, you need to make sure you capture every date/time possibility for that date, so use the following for a filtering condition:

$w("#dataset1").setFilter( wixData.filter()
    .between('image', dateValue1, dateValue2)
 );

@tony-brunsman Perfect! That seems to be working now! Thank you for all your help