Comparing dates in custom code

Hey everyone, i’m trying to use a date pulled from my CMS in an embedded code block, which would attach a different event listener to my button depending upon if the date has passed or not.

Is this something I would need to use a library like Moment.js for? How would I go about doing this?

This is the general idea of what i’m trying to do:

<script>
var myButton = document.getElementById('myButton');     

var date = *date pulled from CMS item*

if (date has passed) {
   myButton.addEventListener("click", function() {
            Calendly.initPopupWidget({ url: 'https://calendly.com/myorg/event1' });
     return false;
     })
} else {
   myButton.addEventListener("click", function() {
            Calendly.initPopupWidget({ url: 'https://calendly.com/myorg/event2' });
     return false;
     })
}

</script>

I’m not sure why you need custom code ? Could you explain in more detail what you want to do and what your cms item contains ?

Because with webflow you can already, and no-code required :
You can have conditional visibility with cms items linked to dates. Therefore you can compare with today and have 2 different buttons.
If date is x and after today, show button a. If date is y before today, show button b.

This is what i get for working at 4am, over-engineering a simple problem. Thank you!