Originally Posted by Beauford
<span id = "message"></span>
var today = new Date(); // the date each day
var oneday = 1000 * 60 * 60 * 24; // The number of milliseconds in one day
var dx_ms = startDate.getTime(); // Convert both dates to milliseconds
var dy_ms = today.getTime();
// Calculate the difference in milliseconds
var difference_ms = Math.abs(dy_ms - dx_ms);
// Convert back to days
var diff = Math.floor(difference_ms/oneday);
document.getElementById("message").innerHTML = "The number of days is without an accident is " + diff;
The simplest way to rest the counter to 0 is to change the startDate value to the now current date. You could use a cookie, but the snag of that is if the cookie is deleted then the code reverts to the original start date.
@chrishurst - why do you think that a file is required?
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.