daily pastebin goal
1%
SHARE
TWEET

TimeCalc.php

depwl9992 Jun 6th, 2018 (edited) 3 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <form action="timecalc.php" method="post">
  2. <textarea name="timelist" cols=10 rows=10></textarea><br/>
  3. <input type='submit'/>
  4. </form>
  5.  
  6.  
  7. <?php
  8.  
  9. if (!empty($_POST['timelist'])) {
  10.         $lines = explode("\n",$_POST['timelist']);
  11.         $fHrs = 0;
  12.         foreach ($lines as $v) {
  13.                 $timeParts = explode(":",$v);
  14.                 $hrs = 0;
  15.                 $mins = 0;
  16.                 $secs = 0;
  17.  
  18.                 if (count($timeParts) == 1) {
  19.                         $secs = intval($timeParts[0]);
  20.                 } elseif (count($timeParts) == 2) {
  21.                         $secs = intval($timeParts[1]);
  22.                         $mins = intval($timeParts[0]);
  23.                 } elseif (count($timeParts) <= 3) {
  24.                         $secs = intval($timeParts[2]);
  25.                         $mins = intval($timeParts[1]);
  26.                         $hrs = intval($timeParts[0]);
  27.                 }
  28.                 $fHrs += $secs/3600 + $mins/60 + $hrs;
  29.         }
  30.         $totalHrs = floor($fHrs);
  31.         $fMins = 60*($fHrs - $totalHrs);
  32.         $totalMins = floor($fMins);
  33.         $fSecs = 60*($fMins - $totalMins);
  34.         $totalSecs = floor($fSecs);
  35.         echo "<h3>Racked up " . $totalHrs . ":" . $totalMins . ":" . $totalSecs . "!</h3>";
  36. }
  37.  
  38. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top