Hello everyone,
I have a repeater that is displaying data from a collection (newest content published). I created a red text box (saying that a content has just been haded, “new”) and I want it to appear for 2 weeks on each new content, then it has to disappear.
So, I was trying to get the created date from the dataset (automatically generated by Wix), add 14 days to it, and compare it to the current date. The box “New” has to appear until current date > created date+14d.
In order to do that, I first tried to see on other posts if someone had the same issue. I mixed up some solutions and ended up with somthing like this :
import wixData from 'wix-data';
export function box24_viewportEnter(event) {
function difference(dateOne, dateTwo) {
let item = $w("#dataset3").getCurrentItem();
let dateField = item._createdDate;
dateField = dateField.toLocaleDateString();
let startDate = (dateField);
var startTimeStamp = (startDate).getTime();
let endDate = new Date(dateTwo);
var endTimeStamp = (endDate).getTime();
var microSecondsDiff = Math.abs(startTimeStamp - endTimeStamp);
//24 hrs/day * 60 minutes/hour * 60 seconds/minute * 1000 msecs/second
var daysDiff = Math.floor(microSecondsDiff / (1000 * 60 * 60 * 24));
console.log("days diff: " + daysDiff);
if (daysDiff > 14) {
$w('#box24').hide() ;
} else {
$w('#box24').show() ;
}
}
}
But as you can see, I am only a beginner with javascript, and this is still not working.
Here is the final result that I want (litlle red box on the top right corner) :
And I finally want to say that I am sorry for my quite bad level of english, i tried hard to describe clearly my problem without using any translator
Kind regards,
Clément