- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to store time created in a MySQL table?
You can use DEFAULT CURRENT_TIMESTAMP. Keep in mind that it will work only at the time of insertion. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Arrivaltime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); Query OK, 0 rows affected (0.31 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Arrivaltime) values('2018-01-31 10:34:56'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Arrivaltime) values('2019-01-31 11:10:12'); Query OK, 1 row affected (0.04 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+---------------------+ | Id | Arrivaltime | +----+---------------------+ | 1 | 2018-01-31 10:34:56 | | 2 | 2019-05-02 12:50:24 | | 3 | 2019-01-31 11:10:12 | +----+---------------------+ 3 rows in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google