Expiring out of date items from a repeater. "Bad format, must be HH:MM, HH:MM:SS, or HH:MM:SS"

Hi, I am trying to expire items from a repeater, when their date has passed. I am filtering the dataset within onReady as I need the items filtered on load. I also have additional wixData.query filters later on in the code - within Timmons and Garwood functions, and so need to define “today” for them, hence the code outside onReady. The code works to some extent - but I am getting the Wix code SDK error - “The value of value parameter that is passed to the value method cannot be set to the value . Bad format, must be HH:MM, HH:MM:SS, or HH:MM:SS.mmm format.” My “date” field is a Date & Time field in the format “02/08/20 09:30”. I have also tried setting the hours and minutes separately but that does not seem to help. I would appreciate any guidance anyone would like to offer. Many thanks, David.

$w.onReady(() => {
loadTimmons();
loadGarwood();
$w (“#dataset1”).onReady(() => {
let today = new Date();
console.log(today);
today.setHours(0, 0);
console.log(today);
$w(“#dataset1”).setFilter(wixData.filter()
.ge(“date”, today)
);
});
});

let today = new Date();
console.log(today);
today.setHours(0, 0);
console.log(today);

As you said you are getting the value from your date and time field so you are getting both the date and time returned in your value.

Try looking at using toTimeString or toLocaleTimeString for this.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString

Wix also already has a page about formatting dates which you can easily use for time as well.
https://support.wix.com/en/article/corvid-formatting-dates

You can also find previous posts about this if you search the forum.
https://www.wix.com/corvid/forum/community-discussion/date-and-time-format-in-a-database
https://www.wix.com/corvid/forum/community-discussion/presenting-time-from-date-and-time-field-on-a-table

For future reference, note that there is a time field available to you as well as the date and time field. so if you were ever needing just time, you can use the time field instead of having to strip it from the date and time field.

Hi GOS, thank you very much for your reply and links.

I do also have the time in a separate time field and have previously tried referencing this field, instead of the date & time field, but the expiry of the items did not work. I think this is because the date is required to expire items.

I think the SDK error message has occurred because JavaScript requires time in 24 hour format and the content manager currently only stores time in 12 hour format. Therefore, I have been looking at extracting the date only from the date & time field as I am happy that items only get expired at the end of the day, rather than instantly, so perhaps I can do without the time portion of the expiry code altogether. I see there is a toDateString but I am not sure how to filter items in the dataset by only the date portion of the date & time field, where this date is greater than or equal to today. .

I am assuming the SDK error that I get when trying to expire the items accounts for the following code stopping working. The following code worked beautifully before I introduced the code to expire the items i.e. the code in my original query, above.

$w(‘#dataset1’).setFilter(newFilter)
.then(() => {
if ($w(‘#dataset1’).getTotalCount() ===0) {
$w(‘#text1’).show();
}
else {
$w(‘#text1’).hide();
}
})
. catch ((err) => {
console.log(err);
});

Now text1 - “No results, please search again” - shows every time the user returns to the page displaying the results of their most recent search, irrespective of the number of results. By changing 0 to 1, the code works correctly, with the text showing only when there is 1 result. Similarly the code works when the number is changed to 2, 3, 4 etc. It just doesn’t work with 0 any more, which is what is needed.

Search previous forum posts and you will find…
https://www.wix.com/corvid/forum/community-discussion/hiding-an-item-in-a-repeater-after-it-expires

Or set up job scheduler to tick your items that have passed and simply filter your repeater with that boolean field, so if field is ticked the repeater does not show it.
https://www.wix.com/corvid/forum/community-discussion/scheduled-job-is-not-working