How can PHP developers ensure that their scripts account for year changes when setting up date ranges?

When setting up date ranges in PHP scripts, developers should account for year changes to ensure accurate date calculations. One way to do this is by checking if the end date falls before the start date and adjusting the end date accordingly by incrementing the year. This can be achieved by comparing the timestamps of the start and end dates and modifying the end date if necessary.

$start_date = strtotime('2021-12-30');
$end_date = strtotime('2022-01-02');

if ($end_date < $start_date) {
    $end_date = strtotime('+1 year', $end_date);
}

echo date('Y-m-d', $start_date) . ' - ' . date('Y-m-d', $end_date);