Date Difference Helper Function

Public

Calculates difference between current date and given date in arguments.Can be changed to use in different ways as per need. Returns the difference in minutes.

</> CopyGet raw version
php
  1. function get_time_diff_in_minutes($time_given) {
  2. if ($time_given != '') {
  3. $time = time();
  4. $current_time = date('Y-m-d H:i:s', $time);
  5. $current_time_object = new DateTime($current_time);
  6. $time_given_object = new DateTime($time_given);
  7. $interval = date_diff($current_time_object, $time_given_object);
  8. $minutes = $interval->days * 24 * 60;
  9. $minutes += $interval->h * 60;
  10. $minutes += $interval->i;
  11. return $minutes;
  12. }
  13. }