Hi all,
Need some help with code that knows to display a certain text according to today’s date. I want to create a db with a date column, a text column and a link column. Final result: each day a different text and link will show in the page according to the current date.
Any suggestions and examples will be gladly accepted
Thank you.
So have a date field (type:Date&Time) in your collection.
In the date field put all your time in hours to be 00:00;
Then when the page loads query it:
import wixData from 'wix-data';
let todayTime = new Date();
let yesterday = new Date(todayTime - 864 * 100000);
//put the following code inbnside $w.onready() function
wixData.query("CollectionName")
.le(todayTime)
.gt(yesterday)
.find()
.then((res) => {
if(res.items.length > 0) {
let item = res.items[0];
$w("#text1").text = item.text;
//etc...
}
})
Thank you!! I’ll give it a try.