0

I have a progress bar that looks LIKE THIS

I also have a table for each user called time (which is a future expirey date. For example 1 day ahead, 1 week ahead... anything bigger than now).

I have made it so it calculates how many days, hours and minutes they have left until the time has been reached using the following code :

  <?php
    foreach($users as $user) {
      $now = new DateTime();
      $clientTime_console = $user[11]; $future_date_console = new DateTime($clientTime_console); $interval_console = $future_date_console->diff($now);
    }
  ?>

Then I call this by using :

<?php foreach($users as $user) { echo $user[11] != '' ? $interval_console->format("<b>%a</b>d <b>%h</b>h <b>%i</b>m") : 'Not set'; } ?>

That works.

But then my progress bar. I want 100% to be the amount of time they originally were given and then for the progress bar to go down as their days pass.

I'm not sure how I would do this.

If I need another table or anything, could anyone let me know ?

Note that I add users or update users using my backend so I could possibly make a table called last-time-given and then update it when I either add or update a users time.

My progress bar is this :

<div class="bar -info" style="width: 80%;"></div>

As you can see, it's done by the width so I would need to put in the style, a percentage.

1 Answer 1

2

Have something like that:

    <div class="bar -info" style="width: 
 <?php echo (strval($future_date_console->diff($now).s / $now->diff($total_time_allow).s)+"%");?>
    ;"></div>

If think you can adapt it to your need

Sign up to request clarification or add additional context in comments.

5 Comments

I made a definition for $total_time_allow which is $total_time_allow = date('Y-m-d H:i:s', strtotime("+7 day")); and it still doesn't show the bar.
Does the PHP return a correct value? you can just echo the returned value somewhere else to check.
Okay it returned an error of : Object of class DateInterval could not be converted to string
Edited the answer
@n.nachury I still have an error - : Object of class DateInterval could not be converted to string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.