Business days with DATADIFF

Asked

Viewed 25 times

0

Good morning, I would like to take only the working days taking advantage of the code below, already tried several ways and could not. Can someone help me?

 $result_pesquisar = "SELECT *
        FROM horascorridas JOIN departamentos ON (horascorridas.subcategoria_id=departamentos.id)
        WHERE horascorridas.categoria_id = '$id_categoria' AND horascorridas.subcategoria_id = '$id_sub_categoria' LIMIT $inicio, $qnt_result_pg";
        $resultado_pesquisar = mysqli_query($conn, $result_pesquisar);       
        while ($row_pesquisar = mysqli_fetch_assoc($resultado_pesquisar)){


        //Seta a data padrão pro php reconhecer o formato d/m/Y
        date_default_timezone_set('America/Bahia');

        //Cria a data de inicio e fim convertendo a string em formato brasileiro pro formato americano

        $data_inicio = new DateTime($row_pesquisar['created'].' '.$row_pesquisar['horainicio']);
        $data_final = new DateTime($row_pesquisar['modified'].' '.$row_pesquisar['horafinal']);


        //Pega a diferença das datas               
        $diff = $data_final->diff($data_inicio);



          echo '
            <tr class="tabela">
              <td style="text-align:center;">'.utf8_encode($row_pesquisar['usuarioNome']) .'</td>
              <td style="text-align:center;">'.utf8_encode($row_pesquisar['nome_depart']).'</td>
              <td style="text-align:center;">'.$row_pesquisar['OS'].'</td>
              <td style="text-align:center;">'.$row_pesquisar['horainicio'].'</td>
              <td style="text-align:center;">'.$row_pesquisar['horafinal'].'</td>
              <td style="text-align:center;">'.date('d/m/Y', strtotime($row_pesquisar['created'])).'</td>
              <td style="text-align:center;">'.date('d/m/Y', strtotime($row_pesquisar['modified'])).'</td>
              <td style="text-align:center;">'.($diff->h + ($diff->d * 24)) .':'. $diff->format('%I:%S').'</td>
              <td style="text-align:center;">'.$diff->format('%d').'</td>
                            <tr>';

        }
  • @Anderson Carlos Woss, I believe the question is not duplicated, because my code is different from the one you say is similar.

  • 1

    It is not a question of being equal codes, but of equal solutions. Don’t you need to count the number of working days between dates? If yes, it is the same solution. If not, maybe I misunderstood and perhaps it would be interesting to add more details in the question.

  • @Anderson Carlos Woss, I really need to count the number of working days between dates. And excuse my lack of knowledge, but I couldn’t adapt my code to what you proposed, could help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.