Home  »  CodeGuidesLibrariesProgrammingSnippetsTechnology   »   Check if Date is Greater Than Today Using PHP

Check if Date is Greater Than Today Using PHP

Posted: May 11, 2022 | by Michael Bright

Use this code snippet to check if date is greater than today.

$date_today = new DateTime();
$existing_date = new DateTime( "01/02/2023" );

if ( $date_today > $existing_date ) {

   echo "greater than today";

} else {

   echo "Less than today";

}

Alternate:

$date_today = date("Y-m-d");
$existing_date = "2023-01-02";

if ( $date_today > '2016-01-02') {

   echo "greater than today";

} else {

   echo "Less than today";

}

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.