I have been working with OrangeHRM for a project. It uses the Yui Calendar. I have been working on the leave module. The Leave module lets the user choose a From and To Date – A time frame for which he wants to apply leave !
I want to show the number of Working Days once the user has chosen the dates . A Simple Subtract statement would not work because I want to exclude the Saturdays and Sundays from the equations since they don’t count as working days !
function fillToDate(frmLeaveApp) {
var fromdate = frmLeaveApp.elements['txtLeaveFromDate'];
var todate = frmLeaveApp.elements['txtLeaveToDate'];
var result = frmLeaveApp.elements['txtLeaveTotalDay'];
if(!fromdate || !todate || !result) {
return;
}
var a = fromdate.value;
var b = todate.value;
var c = a.split('-');
var d = b.split('-');
var ac = new Date();
ac.setFullYear(c[2], c[1], c[0]);
var bd = new Date();
bd.setFullYear(d[2], d[1], d[0]);
result.value = (bd.getTime() - ac.getTime()) / (60*60*24*1000);
}
How do I do it ? Thanks in advance !
Not super proud of this solution – must be more elegant ways, but it should work – does not handle national holidays yet
Demo here