What are the advantages of using NOW() in MySQL queries for datetime values instead of formatting dates in PHP before insertion?

Using NOW() in MySQL queries for datetime values instead of formatting dates in PHP before insertion can simplify the code and reduce the chances of errors related to date formatting. It ensures that the date and time are accurate and consistent across all database entries. Additionally, it can improve performance by reducing the amount of data transferred between PHP and MySQL.

// Example of inserting a record with the current datetime using NOW() in MySQL query
$query = "INSERT INTO table_name (column_name, datetime_column) VALUES ('example_value', NOW())";
$result = mysqli_query($connection, $query);

if($result){
    echo "Record inserted successfully.";
} else{
    echo "Error inserting record: " . mysqli_error($connection);
}