I'm making a site page for school where a person can put in two dates:
- day started working for company
- day stopped working for company (when the contract ends)
these days are filled in via the format MM-DD-YYYY
When a person fills in a start date it'll calculate the following formula: "days worked = todays date - the date that the person has started working" after that it'll calculate it into days instead of miliseconds (days worked/1000/60/60/24).
Now i have to get rid of the Saturday
and Sunday
of every week that one person has worked.
Edit: It has been Fixed, Thanks all
Javascript Code
function days_of_a_year(year) { return isLeapYear(year) ? 366 : 365; }
function isLeapYear(year) { return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0); }
var year = moment().year();
var days_year = days_of_a_year(moment().year());
$(document).ready(function(){
$(".form-control").keyup(function(){
//get
var leave_days = $('#leave_days').val(),
leave_hours = $('#leave_hours').val(),
hours_employee_week = $('#hours_employee_week').val(),
hours_week = $('#hours_week').val(),
date_employed = $('#date_employed').val(),
date_unemployed = $('#date_unemployed').val(),
start = new Date(date_employed),
end = new Date(date_unemployed),
diff = new Date(end - start),
days = Math.round(diff/1000/60/60/24),
now = new Date(),
days_worked = new Date(now - start),
year = moment().year();
var leave_hours_full = leave_days * leave_hours;
var perc_employment = hours_employee_week / hours_week * 100;
var leave_hours_year = leave_hours_full * (hours_employee_week / hours_week);
var days_worked_year = Math.round(days_worked/1000/60/60/24);
console.log(parseInt(days_worked_year));
$('#days_worked_year').val(days);
$('#days_full_year').val(days_year);
$('#perc_worked_year').val(days_worked_year);