PHP Time Remaining Percentage

I am creating a system maintenance page that shows when system maintenance is performed. There is a progress bar on the page that shows which part of the service has been completed. I am trying to automate the progress bar by calculating the percentage / time remaining in the system maintenance window, but I am having problems.

There are three different times in the database, the start time, the end time, and then the current time. I need to sort out the remaining maintenance work time and show it in the progress bar coming from 1% to 100%. The script should be able to calculate how much time has passed between the start time and the end time.

At first I tried to calculate the percentage between two times (current time and end time), but that would not work, because there should be three factors in the equation: start time, end time and current time.

Any help on this would be appreciated.

+3
source share
2 answers

I assume that you save the start and end times as unixtimestamp.

Essentially, all you have to do is find out the percentage of elapsed seconds and the total number of seconds.

So something like:

$total_secs = $end_time - $start_time;

$elapsed_secs = time() - $start_time;

$percent = round(($elapsed_secs/$total_secs)*100);
+4
source

To get the percentage completed, it will be as follows:

$ completed = (($ current - $ start) / ($ end - $ start)) * 100;

+3
source

All Articles