What are the advantages of using DATETIME over timestamp for date manipulation in MySQL and PHP?

When working with dates in MySQL and PHP, using DATETIME over timestamp offers more flexibility and precision for date manipulation. DATETIME allows for a wider range of dates to be stored and manipulated accurately, as it does not have the same limitations as timestamp. Additionally, DATETIME values are not affected by time zone changes, making them more reliable for storing and retrieving dates.

// Example of using DATETIME in MySQL and PHP for date manipulation
// Create a DATETIME column in MySQL table
$query = "CREATE TABLE events (
    id INT AUTO_INCREMENT PRIMARY KEY,
    event_name VARCHAR(255),
    event_date DATETIME
)";

// Insert a new event with a DATETIME value
$query = "INSERT INTO events (event_name, event_date) VALUES ('Birthday Party', '2022-05-15 18:00:00')";

// Retrieve events that occur after a certain date
$today = date('Y-m-d H:i:s');
$query = "SELECT * FROM events WHERE event_date > '$today'";