calculate time from a html table

  html, javascript, php

I am currently creating a working time account,
the times you enter daily are displayed in a table, the total working time per working day is also calculated and break times are also deducted.

Now to my question, i am looking for a solution to calculate the total time in the table but i don’t know how to start.

e.g.

  • 01.10.2020 8:00 hours

  • 02.10.2020 8:30 hours

  • 03.10.2020 8:30 hours

Output = 24:00 hours

I hope you can help me with that. 🙂

require("../core/App_Time/connect.php");
$user = $_SESSION['id'];

$sql = ("SELECT * FROM times WHERE user='$user'");
    $result = mysqli_query($db, $sql);

    if (mysqli_num_rows($result) > 0) {
      
      while($row = mysqli_fetch_assoc($result)) {
        $strStart = $row['vhour'].':'.$row['vmin'];
        $strEnd   = $row['nhour'].':'.$row['nmin'];
        $pause = $row['pause'];
        
        $dteStart = new DateTime($strStart);

        $dteEnd   = new DateTime($strEnd);
     
        $dteDiff  = $dteStart->diff($dteEnd->modify(-$pause .'minutes'));
        $formatTime = $dteDiff->format("%H:%I");
        $gesammt = $dteDiff->format("%H");

        $formatA = $row['vhour'] . " : " . $row['vmin'];
        $formatB = $row['nhour'] . " : " . $row['nmin'];
        $formatDate = $row['days'] . "." . $row['monat'] .".". $row['jahr'];

        echo '
        <tr id="' .$row['id']. '">
            <th>' .$row['id']. '</th>
            <th>'.$row['ort'].'</th>
            <td>'.$formatTime.' Stunden</td>
            <td>'.$formatA.'</td>
            <td>'.$formatB.'</td>
            <td>'.$formatDate.'</td>
        </tr>
        ';
       
      }
    } else {
        echo '
        <tr>
            <th>NULL</th>
            <td>0 Stunden</td>
            <td>00:00</td>
            <td>00:00</td>
            <td>01.01.1999</td>
        </tr>
        ';
    }
    
    mysqli_close($db);

?>```

[enter image description here][1]


  [1]: https://i.stack.imgur.com/7qnKF.png

Source: Ask PHP

LEAVE A COMMENT