Insert Timestamp in MySQL
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Inserting timestamps in MySQL databases is a fundamental task for engineers working with time-sensitive data. This guide covers how to properly create and insert timestamp values in MySQL, including usage in MySQL Workbench.
MySQL handles timestamps as a type of data that records the date and time. The TIMESTAMP data type is useful for recording events, logging, and time-stamping records.
To start, create a table with a TIMESTAMP column. This can be achieved using the CREATE TABLE command.
CREATE TABLE example_table (
id INT AUTO_INCREMENT PRIMARY KEY,
event_name VARCHAR(100),
event_timestamp TIMESTAMP
);
For inserting the current timestamp, MySQL provides the CURRENT_TIMESTAMP function. This automatically inserts the current date and time.
INSERT INTO example_table (event_name, event_timestamp)
VALUES ('Event Name', CURRENT_TIMESTAMP);
To insert a custom timestamp, simply specify it in the YYYY-MM-DD HH:MM:SS format.
INSERT INTO example_table (event_name, event_timestamp)
VALUES ('Event Name', '2023-01-01 12:00:00');
If you want a timestamp to be automatically added when a new record is created, set the TIMESTAMP column to default to CURRENT_TIMESTAMP.
ALTER TABLE example_table
MODIFY event_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
In MySQL Workbench, you can insert timestamps similarly to how you would in a standard MySQL environment. Use the SQL Query tab to run your INSERT statements.
Consider inserting timestamps when tracking events, logging user actions, or recording data changes. This practice aids in data auditing and time-based analysis.
If this query pattern is part of recurring reporting, Basedash helps you turn it into reusable, AI-native BI workflows: prompt-to-SQL, shared dashboards, and trusted answers that stay aligned with your data model.
Remember, handling timestamps effectively is crucial in data management and analysis, and understanding how to insert and use them in MySQL is a key skill for any engineer working with databases.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.