How can the DateTime class be utilized effectively in PHP for handling time intervals in a booking system?

When working with time intervals in a booking system, the DateTime class in PHP can be utilized effectively to calculate durations, check availability, and manage bookings. By creating DateTime objects for the start and end times of bookings, you can easily calculate the duration between them using the `diff()` method. This allows for efficient handling of time intervals and ensures accurate booking management.

// Example code snippet for handling time intervals in a booking system using DateTime class

// Create DateTime objects for start and end times
$start = new DateTime('2022-01-01 10:00:00');
$end = new DateTime('2022-01-01 12:00:00');

// Calculate duration between start and end times
$duration = $start->diff($end);

// Output duration in hours and minutes
echo "Duration: " . $duration->h . " hours, " . $duration->i . " minutes";