Streaming live at 10am (PST)

Need help with hiding Divs in a collections based on time

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.

Webflow does allow filtering of the list based on the day but not based on time
So can anyone help me with this?

@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.

Let me know,

Sam

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.

Here’s the read-only link:


Currently, desktop-view is hidden, only mobile-view is accessible.

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?

yes. to give an example, a discount coupon released on a specific time available for a limited time

@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).

1 Like

@Rahul_Darekar - take a look at this codepen:

I think it is functioning relatively well, although comparing dates / times is always more complicated than it seems like it should be.

1 Like

thanks for replying.
Code for comparing time and getting the output works fine.

The problem seems to be with styling properties.

@Rahul_Darekar - can you PM me a login so I can see this actually functioning?

I am using google SSO.
I can clone the site if you want

@Rahul_Darekar - sure, can you publish the cloned version as well?


Posting here so other members can see it too.
Note: Only Mobile view is visible, desktop view is currently hidden

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. https://momentjs.com/docs/

Chris, day.js is much smaller and use the same structure. Moment is done and won’t be further developed.


guys this is the same code which I am using in the webflow.
Somehow this works in js.do but doesnt work in webflow.