PHP Tutorial: How to Check Date is Today Date

Share

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

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