Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_host = 'localhost'; // Server Name
- $db_user = 'root'; // Username
- $db_pass = ''; // Password
- $db_name = 'login'; // Database Name
- $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
- if (!$conn) {
- die ('Failed to connect to MySQL: ' . mysqli_connect_error());
- }
- $counter=0;
- $sql = "SELECT `OrderID`,`CIDateTime`,`CODateTime` from overall";
- $query = mysqli_query($conn, $sql);
- if (!$query) {
- die ('SQL Error: ' . mysqli_error($conn));
- }
- while ($row = mysqli_fetch_array($query))
- {
- $startTS = strtotime($row['CIDateTime']);
- $endTS = strtotime($row['CODateTime']);
- $start_TS = date('H:i',strtotime($row['CIDateTime']));
- $end_TS = date('H:i',strtotime($row['CODateTime']));
- $start='08:30';
- $start = strtotime($start);
- $end='17:00';
- $end = strtotime($end);
- if($start_TS >= '08:30')
- {
- if(date('Y-m-d', $startTS) == date('Y-m-d', $endTS))
- {
- if($start_TS >= '08:30' && $end_TS == '00:00')
- {
- $work_seconds = round((time() - $startTS)/60,0);
- $hour = floor($work_seconds / 60).':'.($work_seconds -
- floor($work_seconds / 60) * 60);
- $hours=floor($hour);
- }
- elseif($start_TS >= '08:30' && $end_TS <= '13:00')
- {
- $work_seconds = round(($endTS - $startTS)/60,0);
- $hour = floor($work_seconds / 60).':'.($work_seconds -
- floor($work_seconds / 60) * 60);
- $hours=floor($hour);
- }
- elseif($start_TS >= '13:30' && $end_TS <= '17:00')
- {
- $work_seconds = round(($endTS - $startTS)/60,0);
- $hour = floor($work_seconds / 60).':'.($work_seconds -
- floor($work_seconds / 60) * 60);
- $hours=floor($hour);
- }
- elseif($start_TS >= '08:30' && $end_TS <= '17:00')
- {
- $work_seconds = round(($endTS - $startTS - 1800)/60,0);
- $hours = floor($work_seconds / 60).':'.($work_seconds -
- floor($work_seconds / 60) * 60);
- $hours=floor($hour);
- }
- }
- if(date('Y-m-d', $startTS) != date('Y-m-d', $endTS))
- {
- if($start_TS >= '08:30' && $end_TS <= '17:00')
- {
- $start_TS = strtotime($start_TS);
- $end_TS = strtotime($end_TS);
- $a=($end-$start_TS)/60;
- $b=($end_TS-$start-1800)/60;
- $minutes=$a+$b;
- $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
- 60) * 60);
- }
- elseif($start_TS >= '13:30' && $end_TS >= '13:30')
- {
- $start_TS = strtotime($start_TS);
- $end_TS = strtotime($end_TS);
- $a=($end-$start_TS)/60;
- $b=($end_TS-$start-1800)/60;
- $minutes=$a+$b;
- $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
- 60) * 60);
- }
- elseif($start_TS >= '13:30' && $end_TS <= '13:00')
- {
- $start_TS = strtotime($start_TS);
- $end_TS = strtotime($end_TS);
- $a=($end-$start_TS)/60;
- $b=($end_TS-$start)/60;
- $minutes=$a+$b;
- $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
- 60) * 60);
- }
- elseif($start_TS >= '08:30' && $end_TS <= '13:00')
- {
- $start_TS = strtotime($start_TS);
- $end_TS = strtotime($end_TS);
- $a=($end-$start_TS-1800)/60;
- $b=($end_TS-$start_TS)/60;
- $minutes=$a+$b;
- $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
- 60) * 60);
- }
- }
- }
- echo '<tr>
- <td>'.++$counter.'</td>
- <td>'.$row['OrderID'].'</td>
- <td>'.$row['CIDateTime'].'</td>
- <td>'.$row['CODateTime'].'</td>
- <td>'.$hours.' Hrs</td>
- </tr>';
- }
- ?>
Add Comment
Please, Sign In to add comment