How to calculate hours between two dates in php?

In this tutorial, we are using PHP date time functions to calculate the hour difference between two dates.

1. Code:

  <?php 	
	function getDifferenceHourOfTwoDates($date1, $date2){
		$date1 = strtotime($date1);
		$date2 = strtotime($date2);
		return ($date1 - $date2) / 3600;
	}
	$date1 = "24-06-2022 2:3:33";
	$date2 = "20-06-2022 2:30:00";
	echo(getDifferenceHourOfTwoDates($date1, $date2));
    ?> 

2. Example:

Input:

"24-06-2022 2:3:33";
"20-06-2022 2:30:00";

Output:

95.559166666667