Hi guys!
I want to hide an element when it’s a certain time of the day, except for weekends. So basically, I want the $w(‘#XXX’).hide code to run on Mon to and incl. Fri, between 8:30 AM and 3:30 PM. Is this possible?
Thanks!!!
Edit: The solution is:
let nowTime = new Date(),
today = nowTime.getDay(),
hour = nowTime.getHours();
if (today >= 1 && today <= 5 && hour >= 8 && hour <= 15) {
$w("#chat").show;
}
= 1 (from and incl. Monday) && <= (to and incl. Friday)
= 8 (from 8:00 (8 am)) && <= 15 (to and incl. 15:00 (3 pm))
You can also add the minutes the same way.
P.S. needless to say that in case of days of the week, there’s no use for AND (as it can’t be Sunday and Monday at the same time. But you can use && for day + hour for example.)
@webmasterq you’re welcome.
P.S.
The difference between the code you suggested earlier (and meanwhile changed it) and mine is very small. But it may be significant in very rare cases:
let’s say that the new Date().getDay() ran at Sunday 23:59:999 and the following new Date().getHours() ran at Monday 00:00:000 , then it will be treated as Sunday 00:00:000 (which is 24 hours earlier). It’s super rare, but if you can prevent it by running the new Date() one time only, that’s better.
Hi, I’m trying to do something a little similar to this but with a dataset values involved…
I have my Wix Events collection connected to 3 text elements on the page to display the next scheduled event. I want #watchSessionButton to show when the event is live.
I tried to use the info above with the getCurrentItem API to make this happen but it’s not working. I’m sure I’ve done this completely wrong but not sure where to go from here.
Any help would be appreciated!
$w.onReady(function () {
//TODO: write your page related code here...
$w("#eventsDataset").onReady(() => {
let itemObj = $w("#eventsDataset").getCurrentItem();
let eventStart = itemObj.start();
let eventEnd = itemObj.end();
const today = new Date();
if (eventStart <= today && eventEnd >= today ) {
$w("#artistSignupButton").hide();
$w("#watchSessionButton").show();
}
});
});