Guest User

Untitled

a guest
Oct 5th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <?php
  2. $db_host = 'localhost'; // Server Name
  3. $db_user = 'root'; // Username
  4. $db_pass = ''; // Password
  5. $db_name = 'login'; // Database Name
  6.  
  7. $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
  8. if (!$conn) {
  9. die ('Failed to connect to MySQL: ' . mysqli_connect_error());
  10. }
  11.  
  12. $counter=0;
  13. $sql = "SELECT `OrderID`,`CIDateTime`,`CODateTime` from overall";
  14.  
  15. $query = mysqli_query($conn, $sql);
  16.  
  17. if (!$query) {
  18. die ('SQL Error: ' . mysqli_error($conn));
  19. }
  20.  
  21.  
  22. while ($row = mysqli_fetch_array($query))
  23. {
  24.  
  25. $startTS = strtotime($row['CIDateTime']);
  26. $endTS = strtotime($row['CODateTime']);
  27.  
  28. $start_TS = date('H:i',strtotime($row['CIDateTime']));
  29. $end_TS = date('H:i',strtotime($row['CODateTime']));
  30.  
  31.  
  32. $start='08:30';
  33. $start = strtotime($start);
  34. $end='17:00';
  35. $end = strtotime($end);
  36.  
  37. if($start_TS >= '08:30')
  38. {
  39. if(date('Y-m-d', $startTS) == date('Y-m-d', $endTS))
  40. {
  41. if($start_TS >= '08:30' && $end_TS == '00:00')
  42. {
  43. $work_seconds = round((time() - $startTS)/60,0);
  44. $hour = floor($work_seconds / 60).':'.($work_seconds -
  45. floor($work_seconds / 60) * 60);
  46. $hours=floor($hour);
  47. }
  48. elseif($start_TS >= '08:30' && $end_TS <= '13:00')
  49. {
  50. $work_seconds = round(($endTS - $startTS)/60,0);
  51. $hour = floor($work_seconds / 60).':'.($work_seconds -
  52. floor($work_seconds / 60) * 60);
  53. $hours=floor($hour);
  54.  
  55. }
  56. elseif($start_TS >= '13:30' && $end_TS <= '17:00')
  57. {
  58. $work_seconds = round(($endTS - $startTS)/60,0);
  59. $hour = floor($work_seconds / 60).':'.($work_seconds -
  60. floor($work_seconds / 60) * 60);
  61. $hours=floor($hour);
  62.  
  63. }
  64. elseif($start_TS >= '08:30' && $end_TS <= '17:00')
  65. {
  66. $work_seconds = round(($endTS - $startTS - 1800)/60,0);
  67. $hours = floor($work_seconds / 60).':'.($work_seconds -
  68. floor($work_seconds / 60) * 60);
  69. $hours=floor($hour);
  70. }
  71. }
  72. if(date('Y-m-d', $startTS) != date('Y-m-d', $endTS))
  73.  
  74. {
  75. if($start_TS >= '08:30' && $end_TS <= '17:00')
  76. {
  77. $start_TS = strtotime($start_TS);
  78. $end_TS = strtotime($end_TS);
  79. $a=($end-$start_TS)/60;
  80. $b=($end_TS-$start-1800)/60;
  81. $minutes=$a+$b;
  82. $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
  83. 60) * 60);
  84.  
  85. }
  86. elseif($start_TS >= '13:30' && $end_TS >= '13:30')
  87. {
  88. $start_TS = strtotime($start_TS);
  89. $end_TS = strtotime($end_TS);
  90. $a=($end-$start_TS)/60;
  91.  
  92. $b=($end_TS-$start-1800)/60;
  93.  
  94. $minutes=$a+$b;
  95. $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
  96. 60) * 60);
  97. }
  98.  
  99. elseif($start_TS >= '13:30' && $end_TS <= '13:00')
  100. {
  101.  
  102. $start_TS = strtotime($start_TS);
  103. $end_TS = strtotime($end_TS);
  104.  
  105. $a=($end-$start_TS)/60;
  106.  
  107. $b=($end_TS-$start)/60;
  108.  
  109. $minutes=$a+$b;
  110. $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
  111. 60) * 60);
  112.  
  113. }
  114. elseif($start_TS >= '08:30' && $end_TS <= '13:00')
  115. {
  116. $start_TS = strtotime($start_TS);
  117. $end_TS = strtotime($end_TS);
  118. $a=($end-$start_TS-1800)/60;
  119.  
  120. $b=($end_TS-$start_TS)/60;
  121.  
  122. $minutes=$a+$b;
  123. $hours = floor($minutes / 60).':'.($minutes - floor($minutes /
  124. 60) * 60);
  125. }
  126.  
  127. }
  128. }
  129.  
  130. echo '<tr>
  131.  
  132. <td>'.++$counter.'</td>
  133. <td>'.$row['OrderID'].'</td>
  134. <td>'.$row['CIDateTime'].'</td>
  135. <td>'.$row['CODateTime'].'</td>
  136. <td>'.$hours.' Hrs</td>
  137.  
  138. </tr>';
  139.  
  140. }
  141.  
  142. ?>
Add Comment
Please, Sign In to add comment