What is the best practice for storing timestamps in a database for filtering posts by date in PHP?

When storing timestamps in a database for filtering posts by date in PHP, it is best practice to use the DATETIME data type in MySQL to ensure accurate storage and retrieval of date and time information. This allows for easy querying and sorting of posts based on their timestamp values.

// Example of creating a table with a DATETIME column in MySQL
CREATE TABLE posts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    content TEXT,
    created_at DATETIME
);

// Example of inserting a post with the current timestamp
INSERT INTO posts (title, content, created_at) VALUES ('Example Post', 'This is an example post.', NOW());

// Example of querying posts sorted by date
SELECT * FROM posts ORDER BY created_at DESC;