How can mktime() function be utilized to compare timestamps in PHP for date queries?

When comparing timestamps in PHP for date queries, the mktime() function can be utilized to create timestamps for specific dates and times. By using mktime() to generate timestamps for the dates being compared, you can easily compare them using standard comparison operators like greater than (>), less than (<), or equal to (==).

// Create timestamps for two dates to compare
$timestamp1 = mktime(0, 0, 0, 10, 1, 2021); // October 1, 2021
$timestamp2 = mktime(0, 0, 0, 10, 15, 2021); // October 15, 2021

// Compare the timestamps
if ($timestamp1 &lt; $timestamp2) {
    echo &quot;October 1, 2021 is before October 15, 2021&quot;;
} elseif ($timestamp1 &gt; $timestamp2) {
    echo &quot;October 1, 2021 is after October 15, 2021&quot;;
} else {
    echo &quot;October 1, 2021 is the same as October 15, 2021&quot;;
}