calculate datetime difference code example
Example 1: time difference between two datetime.time
dateTimeA = datetime.datetime.combine(datetime.date.today(), a)
dateTimeB = datetime.datetime.combine(datetime.date.today(), b)
dateTimeDifference = dateTimeA - dateTimeB
dateTimeDifferenceInHours = dateTimeDifference.total_seconds() / 3600
Example 2: How to calculate the difference between two dates
$datetime1 = new DateTime('2020-10-11 16:52:52');
$datetime2 = new DateTime('2020-10-13 16:52:52');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%a days');