PHP Tutorial: How to Check Date is Today Date

Use the following code to check a date whether it is today date.

$timestamp = "2022-06-27";
$today = new DateTime("today");
$match_date = DateTime::createFromFormat( "Y-m-d", $timestamp );
$match_date->setTime( 0, 0, 0 );
$diff = $today->diff( $match_date );
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval

if ($diffDays != 0)
{
echo "not today";
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.