What are the best practices for comparing timestamps of different days in PHP?

When comparing timestamps of different days in PHP, it's important to ensure that the timestamps are in the same timezone and format before comparing them. One way to achieve this is by converting the timestamps to a common timezone and format using the DateTime class in PHP. This allows for accurate comparison of timestamps across different days.

$timestamp1 = strtotime('2022-01-01 12:00:00');
$timestamp2 = strtotime('2022-01-02 10:00:00');

$date1 = new DateTime();
$date1->setTimestamp($timestamp1);
$date1->setTimezone(new DateTimeZone('UTC'));

$date2 = new DateTime();
$date2->setTimestamp($timestamp2);
$date2->setTimezone(new DateTimeZone('UTC'));

if ($date1 < $date2) {
    echo "Timestamp 1 is before Timestamp 2";
} elseif ($date1 > $date2) {
    echo "Timestamp 1 is after Timestamp 2";
} else {
    echo "Timestamp 1 is equal to Timestamp 2";
}