So I am creating a website where the user will get to vote between two teams in a match, but I want to allow them to vote within a certain time period, for eg. 1 hour before the match begins. I am currently getting all the content related to the match including time from CMS.
I want to hide divs if the condition doesn’t matches.
I am using following embed code in the collection list with two divs todayschedule and selecttodaysteam.
@Rahul_Darekar - can you post your published and read-only link? It’s hard to troubleshoot custom code without those. But here are a few ideas:
You don’t need to include jQuary again, Webflow includes it automatically.
In jQuery you declare the current datetime like this:
var current = new Date($.now());
Why are you comparing the month, days, and hours instead of just comparing now date to the end time? It seems unnecessarily complicated, could you not just say:
if (new Date($.now()) > new Date('Start Time') && new Date($.now()) < new Date('End Time')) {
//do stuff
}
Again, this is kind of a guess based on your sample code and explanation, seeing the site live would be helfpul.
Hi Sam, thank you for replying.
Previously I tried with this code
`<script>
window.setInterval(function(){
var current = new Date();
var start = new Date(“Start Time”);
var expiry = new Date(“End Time");
// todayschedule and selecttodaysteam are two divs that I want to hide.
if (current.getTime() > start.getTime()) {
$('#todayschedule').hide();
$('#selecttodaysteam').hide();
} else if (current.getTime() < expiry.getTime()) {
$('#todayschedule').hide();
$('#selecttodaysteam').hide();
}
}, 0);
</script>`
But had no luck.
So I tried to compare with month date and hour.
Have updated the current code as you suggested above
`<script>
window.setInterval(function(){
if (new Date() > new Date('Start Time') && new Date() < new Date('End Time')) {
$('#todayschedule').hide();
$('#selecttodaysteam').hide();}
}, 0);
</script>`
PS: A developer friend of mine suggested me to compare each
@Rahul_Darekar - can you describe exactly what you are trying to accomplish?
Based on the code you posted it looks like you want to hide the content if the current datetime is later than the start time and also hide the content if it’s less than the end time? Is that correct?
@Rahul_Darekar - I will take a look at this tonight. I may have given you some bad info about getting the current time, it looks like that may have been deprecated in a newer version of jQuery. This should be totally doable (but also easy to bypass if someone knows how to use dev tools in their browser).
I would consider using moment.js. And then simply defining the hidden combo class and apply the class with jquery in an iterative loop. Simple simon. Moment.js | Docs