Jeff Davidson
Jeff Davidson

Reputation: 1929

Finding time remaining

What would be the correct equation for finding out the variable timeRemaining in minutes.

$lockDate = $row['lockDate'];

                $currentDateTime = time();

                // Find out if user is locked out of their account
                if (($lockDate != "0000-00-00 00:00:00") && strtotime($lockDate) < $currentDateTime) { 

                    $lockDate = strtotime($lockDate);
                    $diff = $currentDateTime - $lockDate;
                    echo $diff;

                    // Take minutes and perform tasks
                    if ($diff <= 600) {

                        // Calculate time remaining
                        $timeRemaining = 10 - $diff;

                        // Account locked error
                        $errors = true;
                        $message = "Your account is currently locked, we appologize for the inconvienence. You must wait " .$timeRemaining." minutes before you can log in again!";

                        $output = array('errorsExist' => $errors, 'message' => $message);

                    } else {

                        // Clear the lock
                      //  $query = "UPDATE manager_users_hacking SET lockDate = NULL, hackerIPAddress = NULL, failedLogins = 0 WHERE userID = '".$userID."'";
                        $result = mysqli_query($dbc,$query);

                    } 

                }

Upvotes: 0

Views: 103

Answers (1)

Daniel Iankov
Daniel Iankov

Reputation: 306

$diff is in seconds. You can convert to minutes by dividing by 60. $diff=$diff/60.

Upvotes: 1

Related Questions