How can DATE_FORMAT be used in the WHERE clause of a SQL query in PHP?

When using DATE_FORMAT in the WHERE clause of a SQL query in PHP, you need to ensure that the date format matches the format stored in the database. You can use the DATE_FORMAT function to format the date in the query to match the database's date format. Example PHP code snippet:

$date = "2022-12-31";
$formatted_date = date("Y-m-d", strtotime($date));

$sql = "SELECT * FROM table_name WHERE DATE_FORMAT(date_column, '%Y-%m-%d') = '$formatted_date'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process the results
    }
} else {
    echo "No results found.";
}