Get the Difference of Two Time using PHP

This tutorial will teach you on how to get the difference of two time in PHP using php shorttime function. This code will help to thus programmer who want to limit the number of attempts in failed login and can login again with the defined time. To understand more about this tutorial, follow the steps bellow.

Creating Our script that get the difference and display the result

The code bellow will subtract and get the difference of two time using the php date and short time function. Copy thye code bellow and paste to your php editor and save it as "index.php".
  1. <?php
  2. $firsttime = strtotime('02:54:17');
  3. $secondtime = strtotime('01:54:17');
  4. $result = $firsttime - $secondtime;
  5. echo 'First Time : '. date('H:i:s', $firsttime).'<br>';
  6. echo 'Second Time : '. date('H:i:s', $secondtime).'<br>';
  7. echo 'Result : '. date('H:i:s', $result);
  8. ?>
Hope this code will help you in your project.

Add new comment