Hide and show an element based on dates.

I would like to show and hide an element based on time of year, For example a button that will only show on the page from November 1 to March 31. But i have no idea how to do this and i haven’t been able to find any examples of this online. The closest i have found was a countdown timer but i don’t know how to modify it to do what i am trying to do. Hre is the countdown code if that would help someone with what i am trying to do.

$w.onReady( function () {
var countDownDate = new Date(“Dec 1, 2018 20:11:25”).getTime(); // Countdown date and time

var x = setInterval( function () {
var now = new Date().getTime();
var distance = countDownDate - now;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    $w("#countDownTimer").text = days + "d " + hours + "h " + minutes + "m " + seconds + "s "; 

if (distance < 0) {
clearInterval(x);
$w(“#countDownTimer”).text = “EXPIRED”;
}
}, 1000);

});

Plus you can also try these links too:

Using disabledDates in DatePicker
Compare two dates with JavaScript
Show, hide Button by date
Working with dates and time in WIX Code?

See the Open for Business example which checks intervals by data and time.

Thanks everyone, I got this to work by using this code

$w.onReady( function () {

var startD = new Date(‘10/01/2018’);
var endD = new Date(‘01/31/2019’);
var today = new Date();
if (startD >= today || endD <= today) {
$w(‘#html4’).hide()
} else {
$w(‘#html4’).show()
}
});

But i have one more question, how can i do this without the year involved so it does this function every year between the start month and end month only. Do i need to define the date format or is there a way to put the date in as 1/1/any? I can’t find anything about dates that tell it to ignore the year just apply to month and day.

Hi @dragonlord4469187 ,

Did you manage to figure out a way to do that?..

 "do this without the year involved so it does this function every year between the start month and end month only"

I am trying to construct a code very similar to yours - and it would be VERY HELPFUL if I could make it work WITHOUT the ‘year’ part!

This feature was fantastic! Although I wish Wix had the option to schedule a candidate site to go public on a specific date, this capability provided here works wonderfully as an alternative. I truly appreciate this code and the invaluable assistance of Chat GPT in enhancing its capabilities. THANKS!