Run Query into MySQL
Let’s take an example and Run each and every query into Database step by step.
Step 1: Create a table in Database.
CREATE TABLE DateAndTime (Date DATE);
Step 2: Show table is created.
SHOW TABLES;
Output:
Step 3: Insert values into table.
INSERT INTO DateAndTime VALUES ('2023-12-31');
Step 4: Now Select whole table to see the values into table.
SELECT * FROM DateAndTime;
Output:
Step 5. Add another columns TIME, DATETIME, and TIMESTAMP into DateAndTime(table).
ALTER TABLE DateAndTime ADD Time TIME;
ALTER TABLE DateAndTime ADD DateTime DATETIME;
ALTER TABLE DateAndTime ADD TimeStamp TIMESTAMP;
Step 6: Insert values into database.
INSERT INTO DateAndTime (Time) VALUES ('14:30:00');
INSERT INTO DateAndTime (DateTime) VALUES ('2023-12-31 14:30:00');
Step 7: Now Select whole table to see all the rows.
SELECT * FROM DateAndTime;
Output:
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.
Contact Us