Php countup from a date

78

<div class="countup" id="countup1">
  <span class="timeel months">00</span>
  <span class="timeel showweeks">00</span>
  <span class="timeel showdays">00</span>
</div>
<script>
// Month, Weeks and days counter
window.onload = function() {
  // Month, Day, Year Hour:Minute:Second, id of element container
  countUpFromTime("Jul 07, 2022 00:00:00", 'countup1'); // !! Change this line !!
};
function countUpFromTime(countFrom, id) {
  countFrom = new Date(countFrom).getTime();
  var now = new Date(),
      countFrom = new Date(countFrom),
      timeDifference = (now - countFrom);
    
  var secondsInADay = 60 * 60 * 1000 * 24,
      secondsInAHour = 60 * 60 * 1000;
    
  	days = Math.floor(timeDifference / (secondsInADay) * 1);
 	 weeks = Math.floor(days / 7);
  	months = Math.floor(weeks / 4)
  	showdays = Math.floor(days - (weeks * 7));
  	showweeks = Math.floor(weeks -(months * 4))
  	years = Math.floor(days / 365);
  if (years > 1){ days = days - (years * 365) }
  	hours = Math.floor((timeDifference % (secondsInADay)) / (secondsInAHour) * 1);
  	mins = Math.floor(((timeDifference % (secondsInADay)) % (secondsInAHour)) / (60 * 1000) * 1);
  	secs = Math.floor((((timeDifference % (secondsInADay)) % (secondsInAHour)) % (60 * 1000)) / 1000 * 1);

  var idEl = document.getElementById(id);
  	idEl.getElementsByClassName('months')[0].innerHTML = months;
  	idEl.getElementsByClassName('showweeks')[0].innerHTML = showweeks;
  	idEl.getElementsByClassName('showdays')[0].innerHTML = showdays;
  
  clearTimeout(countUpFromTime.interval);
  countUpFromTime.interval = setTimeout(function(){ countUpFromTime(countFrom, id); }, 1000);
  </script>

Comments

Submit
0 Comments