Home >Backend Development >PHP Tutorial >How to Compare DateTime Objects in PHP 5.2.8?
PHP 5.2.8 provides two methods for comparing DateTime objects:
$date1 = new DateTime('2023-03-10 15:30:00'); $date2 = new DateTime('2023-03-10 16:00:00'); if ($date1 < $date2) { echo 'Date 1 is earlier than Date 2.' . PHP_EOL; }
$timestamp1 = $date1->getTimestamp(); $timestamp2 = $date2->getTimestamp(); if ($timestamp1 < $timestamp2) { echo 'Date 1 is earlier than Date 2.' . PHP_EOL; }Documentation for Previous PHP Versions
Documentation for previous PHP versions, including 5.2.8, is available on the PHP documentation website:
The above is the detailed content of How to Compare DateTime Objects in PHP 5.2.8?. For more information, please follow other related articles on the PHP Chinese website!