Calculate duration of a projects without week ends and holidays



  • Joel Ordesky

    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
                $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. 

    Comment actions Permalink
  • Georges Blanchard

    Thank you for your answer. 

    I have this code to count the days without the week end

    // 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()),

    // reset time portion

    var day=frD.getDay();
    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?

    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk