What are some common syntax errors to watch out for when using DATE_FORMAT in MySQL queries in PHP?

One common syntax error when using DATE_FORMAT in MySQL queries in PHP is not properly enclosing the date format string in single quotes. Another mistake is using the wrong format characters in the date format string. To avoid these errors, always enclose the date format string in single quotes and use the correct format characters according to MySQL's documentation.

// Correct way to use DATE_FORMAT in a MySQL query in PHP
$dateFormat = 'Y-m-d H:i:s';
$query = "SELECT DATE_FORMAT(date_column, '$dateFormat') AS formatted_date FROM table_name";
$result = mysqli_query($connection, $query);

// Fetch and display the formatted date
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['formatted_date'] . "<br>";
}