Inserting Date-Time Values in MySQL
Using INSERT Statement
To insert the data into the MySQL table you can use the “INSERT” statement with the the format.
Let’s take an example to understand each of the data and time format
1. INSERT syntax for DATE.
INSERT INTO table_name (dateColumn) VALUES ('2023-12-31');
2. INSERT syntax for TIME.
INSERT INTO table_name (timeColumn) VALUES ('14:30:00');
3. INSERT syntax for DATETIME.
INSERT INTO table_name (datetimeColumn) VALUES ('2023-12-31 14:30:00');
4. INSERT syntax for TIMESTAMP.
INSERT INTO table_name (timestampColumn) VALUES (NOW());
“NOW()” function to insert the current date and time.
The “INSERT” query statement is used to inserting values into columns. In above mention queries replace “table_name with your table name in database and also similar add the column names accordingly.
MySQL Insert Date Time
In today’s world, working with data is now a data-to-data activity, so therefore managing data with proper data and time is also crucial. MySQL provides functionalities to handle data and time properly in the database. Understanding how to insert data and time into MySQL database with functions provided by MySQL. Let’s understand with the help of examples.
In this article, we are going discuss how we can deal with date and time in MySQL, As it is very important to set the appropriate data types. MySQL provides data types for saving date and time values, such as DATE, TIME, DATETIME, and TIMESTAMP. Each data type has a specific purpose in MySQL.