How can the BETWEEN operator be correctly used in PHP to compare dates in a MySQL query?

When using the BETWEEN operator in a MySQL query to compare dates in PHP, it's important to format the dates correctly in the query string. Dates should be in the 'Y-m-d' format for MySQL to interpret them correctly. Additionally, the BETWEEN operator is inclusive, so it will include records with dates matching the start and end dates provided.

$start_date = '2022-01-01';
$end_date = '2022-01-31';

$query = "SELECT * FROM table_name WHERE date_column BETWEEN '$start_date' AND '$end_date'";
$result = mysqli_query($connection, $query);

// Process the query result here