Countdown clock months not working

Hi,
I have a countdown clock for a client that needs to ends on 1/9/2023
The days, mins work fine but I cant get the months to work. I have included a read only link below. Can anyone help?

All the clock numbers have Ids.
And this is the code:


Here is my site Read-Only:Webflow - safety-care-partnership

Hi @Julie_Kaye,

Because you’re not using the years, weeks or seconds but they are used in the code there are some errors in the console, I’ve removed them from the below code - would you be able to try replacing your code with this in Page Settings > Custom Code > Before </body> tag:

<script>
(function() {
    var dateDefine = '2023-9-1 00:00';
    var deadline = new Date(dateDefine.replace(/-/g, "/"));
 
   function pad(num, size) {
       var s = "0" + num;
       return s.substr(s.length-size);
   }
 
   function getTimeRemaining(endtime) {
     var t = Date.parse(endtime) - Date.parse(new Date()),
         minutes = Math.floor((t / 1000 / 60) % 60),
         hours = Math.floor((t / (1000 * 60 * 60)) % 24),
         days = Math.floor(t / (1000 * 60 * 60 * 24)),
         months = Math.floor(days / 30)
 
     return {
       'total': t,
       'days': days,
       'hours': hours,
       'minutes': minutes,
       'months': months,
     };
   }
 
   function clock(id, endtime) {
     var days = document.getElementById(id + '-days'),
         hours = document.getElementById(id + '-hours'),
         minutes = document.getElementById(id + '-minutes'),
         months = document.getElementById(id + '-months')
     var timeinterval = setInterval(function() {
       var t = getTimeRemaining(endtime);
 
       if (t.total <= 0){
         clearInterval(timeinterval);
       } else {
   days.innerHTML = pad(t.days, 3);
   hours.innerHTML = pad(t.hours, 2);
   minutes.innerHTML = pad(t.minutes, 2);
   months.innerHTML = pad(t.months, 2);
   }
     }, 1000);
   }
 
   clock('js-clock', deadline);
 })();
</script>

If you’re still having issues after trying this, please let me know and I’ll dig deeper into this issue for you.

That worked :)))) Thank you so much

1 Like