How can the BETWEEN AND operator be effectively used in MySQL queries to handle date and time comparisons?

When using the BETWEEN AND operator in MySQL queries for date and time comparisons, it is important to ensure that the date and time values are properly formatted to avoid unexpected results. One common mistake is not including the time portion when comparing datetime values. To handle this, make sure to include the time portion in the date values being compared. Example PHP code snippet:

// Assuming $start_date and $end_date are properly formatted date strings
$query = "SELECT * FROM table_name WHERE date_column BETWEEN '$start_date 00:00:00' AND '$end_date 23:59:59'";
$result = mysqli_query($connection, $query);

// Process the query result as needed