0

I am working with unix timestamps in a database. I have two times; One of them is stored when the user first logs in, the other is stored one they complete their training.

I have a reporting feature that records the total time (in hours) that the person took to complete the training. I am having a difficult time calculating the end result. (Its possible that the person can finish in less than an hour).

It should also round up to the nearest 15 minute interval. The calculation I am using now is:

<?php
$time_diff = $time_complete - $login_time;
$time_diff = round(round((($time_diff/60)/60),PHP_ROUND_HALF_ODD),2);
?>

The current functionality doesn't have the ability to round to the nearest 15 minute interval, and its showing people under an hour as like 0.26 for example.

Ex0r
  • 27
  • 6
  • If your problem is rounding to 15 minutes then it's just a Math problem. I think you'll need to use `ceil()`. Something like `ceil($minutes / 15) * 15` will round to 15. – Halcyon Jan 31 '17 at 15:54
  • Please show us what you already did yourself. It shouldn't be too hard to get the time taken based on two epoch timestamps. Also what do you mean with the 15 minute interval? – John Smith Jan 31 '17 at 15:56
  • @JohnSmith What i mean, is for example if somebody takes the test, and it takes them an hour and 12 minutes, it should round them up to an hour and 15 minutes. If they take it in an hour and 5 minutes, it should round them down to an hour, etc. Whatever the closest 15 minute interval is to their completed time. Right now, my calculation for time completed is very simple: $time_diff = $time_complete - $login_time; $time_diff = round(round((($time_diff/60)/60),PHP_ROUND_HALF_ODD),2); – Ex0r Jan 31 '17 at 16:01
  • Whoever marked this as a duplicate, it is not. They asked how to round up to the nearest 5 or 10. I asked to the nearest 15, which is also the same solution, however I also asked how to accomodate for if the test is over or under an hour. – Ex0r Jan 31 '17 at 16:35

0 Answers0