What is the difference between using datetime and timestamp in MySQL for storing dates?

When storing dates in MySQL, the main difference between using datetime and timestamp is how they handle time zones and automatic updates. The datetime data type does not account for time zones and does not automatically update when the row is modified. On the other hand, the timestamp data type automatically converts the date and time to UTC when inserting data, and it also automatically updates to the current timestamp when the row is modified.

// Using timestamp data type to store dates in MySQL
$timestamp = date('Y-m-d H:i:s');
$query = "INSERT INTO table_name (timestamp_column) VALUES ('$timestamp')";
$result = mysqli_query($connection, $query);
if($result){
    echo "Date inserted successfully!";
} else {
    echo "Error inserting date: " . mysqli_error($connection);
}