Calculate duration of a projects without week ends and holidays
Hello,
Is it possible to calculate the duration of a project in a calculation field without the weekend and holidays? I have in the same app the start date and the end date of the operation
-
It is possible to count weekdays but probably not business days (meaning excluding holidays).
For Calc you would need a JavaScript formula that looked at if the days were Monday through Friday and only count those days.
Here is a PHP bit of code that does that however, this would need to be converted to JavaScript if you want it to work in a Calc Field.
foo(); function foo() {
$begin = strtotime([start token]);
$end = strtotime([end token]);
if ($begin > $end) {
return "startdate is in the future! <br />";
return 0;
} else {
$no_days = 0;
$weekends = 0;
while ($begin <= $end) {
$no_days++; // no of days in the given interval
$what_day = date("N", $begin);
if ($what_day > 5) { // 6 and 7 are weekend days
$weekends++;
};
$begin += 86400; // +1 day
};
$working_days = $no_days - $weekends;
return $working_days;
}
}
If you look online you might find a JavaScript version or if Rainer is around I am sure he has something already worked up he can share. -
Thank you for your answer.
I have this code to count the days without the week end
Date.prototype.workingDaysFrom=function(fromDate){
// ensure that the argument is a valid and past date
if(!fromDate||isNaN(fromDate)||this<fromDate){return -1;}
// clone date to avoid messing up original date and time
var frD=new Date(fromDate.getTime()),
toD=new Date(this.getTime()),
numOfWorkingDays=1;
// reset time portion
frD.setHours(0,0,0,0);
toD.setHours(0,0,0,0);
while(frD<toD){
frD.setDate(frD.getDate()+1);
var day=frD.getDay();
if(day!=0&&day!=6){numOfWorkingDays++;}
}
return numOfWorkingDays;
};I am trying to get the start and end date of the operation from fields within the app:
fromDate = @Date de début et fin de l'opération
endDate = @Date de début et fin de l'opération
The problem is the date field within the app has 2 dates in it, the start and the end date. is there a way to get them separately?
Please sign in to leave a comment.
Comments
2 comments