troubleshooting Question

javascript counter year to date

Avatar of eezar21
eezar21 asked on
JavaScriptjQueryWeb Languages and Standards
7 Comments1 Solution398 ViewsLast Modified:

I'm trying to create a counter to put on our website to show how many units we have sold this year to date.

I have attached the code below.  I have an average number of 1543 units sold per second, which would give me an approx number of 24 billion by end of June, but I can't seem to reach that number with what I have written.  Also the number generated seems to always start with a rounded number which isn't correct.

Any pointers would be really helpful.

Many thanks



test counter

<div id="counter">


<script type="text/javascript" src=""></script>
// Set the unit values in milliseconds.
var msecPerMinute = 1000 * 60;
var msecPerHour = msecPerMinute * 60;
var msecPerDay = msecPerHour * 24;

// Set a date and get the milliseconds
var date = new Date('1/6/2013');
dateMsec = date.getTime();

// Set the date to January 1, at midnight, of the specified year.
date.setHours(0, 0, 0, 0);

// Get the difference in milliseconds.
var interval = dateMsec - date.getTime(); 

//document.write (interval);

var counter = interval;


function timer() {





Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros