How can timestamps be formatted in PHP to calculate time intervals?
To calculate time intervals in PHP, you can format timestamps using the `strtotime()` function to convert them into Unix timestamps. Then, you can subtract the timestamps to get the time interval in seconds, and format the result as needed using PHP date functions.
$timestamp1 = strtotime('2022-01-01 12:00:00');
$timestamp2 = strtotime('2022-01-01 13:30:00');
$timeInterval = $timestamp2 - $timestamp1;
echo "Time interval in seconds: " . $timeInterval . "<br>";
// Format the time interval as hours and minutes
echo "Time interval: " . floor($timeInterval / 3600) . " hours " . ($timeInterval % 3600) / 60 . " minutes";