# count weeks and days

## Recommended Posts

Hi JavaScript cracks!
I fount that howto and built a countup out of it.
https://www.w3schools.com/howto/howto_js_countdown.asp
This works well, the only thing I struggle is to include weeks. I can calculate the weeks:
var weeks = Math.floor(distance / (1000 * 60 * 60 * 24 * 7));
Bud I can not substract the remaining days, similar to hours, minutes and seconds:
var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 7)) / (1000 * 60 * 60 * 24));
Where ist the problem?

<strong>countup3:</strong>
<p id="countup3"></p>
<script>
// Set the date we're counting up from
var countUpDate3 = new Date("Mar 16, 2020 00:00:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get today's date and time
var now = new Date().getTime();

// Find the distance between now and the count up date
var distance = now - countUpDate3;

// Time calculations for weeks, days, hours, minutes and seconds
var weeks = Math.floor(distance / (1000 * 60 * 60 * 24 * 7));
var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 7)) / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Output the result in an element with id="countup3"
document.getElementById("countup3").innerHTML = weeks + " w " + days + " d " + hours + " h " + minutes + " m " + seconds " s ";

}, 1000);
</script>

##### Share on other sites

It's just mismatched parentheses on this line:

`var days = Math.floor(distance % (1000 * 60 * 60 * 24 * 7)) / (1000 * 60 * 60 * 24));`

Count the opening brackets and the closing brackets.

• 1
##### Share on other sites

Perfect thaks! I must have been blind in one eye.