Advertisement
mirovlad

Round up by 30 minutes

Jul 18th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.33 KB | None | 0 0
  1. $minutes = 153; // 153 == 5*30 + 3
  2. // How many x30 minutes fit in $minutes
  3. $whole = intdiv($minutes / 30); // For 153: intdiv(153, 30) == 5
  4. $remainder = $minutes % 30; // Always 0..29; For 153: 153 % 30 == 3
  5. $roundedMinutes = $whole * 30; // For 153: 5 * 30 == 150
  6. if ($remainder > 0) $roundedMinutes += 30; // For 153: += 30 == 180
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement