What are the benefits of using DateTime over separate columns for date and time in database tables?

When storing date and time information in a database, using a DateTime column instead of separate date and time columns can simplify queries, reduce redundancy, and improve data consistency. DateTime allows for easier manipulation and comparison of date and time values, as well as built-in functions for formatting and calculating date differences.

// Create a table with a DateTime column
CREATE TABLE events (
    id INT PRIMARY KEY,
    event_name VARCHAR(255),
    event_datetime DATETIME
);

// Insert a new event with a DateTime value
INSERT INTO events (id, event_name, event_datetime) VALUES (1, 'Meeting', '2022-10-20 15:30:00');

// Retrieve events that occur after a specific date
SELECT * FROM events WHERE event_datetime > '2022-10-20 00:00:00';

// Update the event datetime value
UPDATE events SET event_datetime = '2022-10-21 10:00:00' WHERE id = 1;