-4

I am working with OT management system. I am calculating some OT value related to the each employee.now i want round up this OT value in last 15 min. How do i do it? Example values are given below.

07:17:46 need to be 07:15:00
06:25:25 need to be 06:15:00

Similar question: Round minute down to nearest quarter hour

Blackbam
  • 17,496
  • 26
  • 97
  • 150
Code Kris
  • 447
  • 3
  • 19
  • `round up` -> `07:17:46` would actually be 8:15 - I believe you want to round down – treyBake Sep 19 '19 at 10:15
  • Not exactly a duplicate as seconds are involved? – Blackbam Sep 19 '19 at 10:41
  • @michmackusa Yes you are right. – Blackbam Sep 19 '19 at 10:46
  • No need to reopen on a slight extension on the seconds. Not every snowflake needs to be saved -- especially when no effort is shown. https://3v4l.org/Bqi4t this is just one random answer from the other page that works just fine. I have voted to delete. – mickmackusa Sep 19 '19 at 10:50

2 Answers2

1

Create your own function to round/floor the value. You can explode the time, then subtract the reminder to make it rounded. Example:

function _floor($time) {
    $elm = explode(':', $time);
    $elm[1] -= $elm[1] % 15;
    $elm[2] = '00';
    return implode(':', $elm);
}

echo _floor('07:17:46') . PHP_EOL;
echo _floor('06:25:25') . PHP_EOL;

Demo at https://3v4l.org/LBKDp

Janie
  • 638
  • 9
  • 26
0

Split into hours, minutes and seconds. Round the minutes down, fill with zeros and return.

function timeLastQuarter($timestr) {
  $time = explode(":",$timestr);
  return str_pad($time[0],2,"0",STR_PAD_LEFT).":".str_pad(((floor($time[1] / 15))*15),2,"0",STR_PAD_LEFT).":00";
}

Example:

echo timeLastQuarter("15:55:00"); // 15:45:00
Blackbam
  • 17,496
  • 26
  • 97
  • 150