Advertisement
Virajsinh

Time Different Find in Php

Jun 10th, 2021
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2.  
  3. //Time Different Find in Two Dates
  4.  
  5. $datetime1 = new DateTime();
  6. $datetime2 = new DateTime('2021-06-10 04:06:06');
  7. $interval = $datetime1->diff($datetime2);
  8. $elapsed = $interval->format('%y years %m months %a days %h hours %i minutes %s seconds');
  9. echo $elapsed;
  10.  
  11. //Time Different Find in Two Dates For Minutes Only
  12. $time = new DateTime("2021-06-10 04:06:06");
  13. $diff = $time->diff(new DateTime());
  14. $minutes = ($diff->days * 24 * 60) +
  15.            ($diff->h * 60) + $diff->i;
  16.            
  17.            echo "<br>".$minutes;
  18. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement