I really need help calculating the difference between two dates and it has to be the number of days in a whole number. Here is my HTML and jQuery..
This is not working at all... The site should say the date today. Then the user would picka date and click the button "Check our safety record" and at the bottom of the page it says how many days it has been. The jQuery:
$(document).ready(function() {
$('#safetyRecord').hide();
var monthNames = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
var newDate = new Date();
newDate.setDate(newDate.getDate());
$('#today').html(dayNames[newDate.getDay()] + "," +' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getDate() + ","+ ' ' + newDate.getFullYear());
/*
$(':button').click(function(){
var start = $('#dateOfLastAccident').val();
var end = $('#today');
var startDate = new Date(start);
var endDate = new Date(end);
var diff = endDate - StartDate;
var numDays = Math.floor( diff / 1000 /60 /60 /24 );
$('#daysSinceLastAccident'+ numDays)();
*/
});
The HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>generic safety</title>
<link rel="stylesheet" href="L3hw.css">
<!-- jQuery library hosted by Google Content Distribution Network -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="L3hw.js"></script>
</head>
<body>
<header>
<img src="images/genericBanner.png" alt="Generic, Inc.">
<p>
The New Ventures Mission is to scout profitable growth opportunities in
relationships, both internally and externally, in emerging, mission-inclusive
markets, and explore new paradigms and then filter and communicate and
evangelize the findings.
</p>
</header>
<section id="main">
<h1>Safety at generic company</h1>
<h2>Today is <span id="today">TBD</span>.<br>
Our last lost-work accident was on
<input type="date" id="dateOfLastAccident">
<button type="button" id="checkRecord">Check our safety record</button>
</h2>
<h2 id="safetyRecord">
It has been <span id="daysSinceLastAccident">TBD</span> days since our last lost-work accident.
</h2>
</section> <!-- end main -->
<footer>
<p id="message">
<!-- (an appropriate safety message will appear here) -->
</p>
<p><img src="images/genericBullet.png" alt="*"> Generic Company - we do stuff</p>
</footer>
</body>
</html>