- 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
Creating a table with a TIMESTAMP field in MySQL?
For this, you can use TIMESTAMP keyword in MySQL.
Let us create a table −
mysql> create table demo50 −> ( −> id int not null auto_increment primary key, −> start_date timestamp default current_timestamp not null, −> end_date timestamp default current_timestamp not null −> ); Query OK, 0 rows affected (1.35 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo50 values(); Query OK, 1 row affected (0.15 sec) mysql> insert into demo50(end_date) values('2020−12−21'); Query OK, 1 row affected (0.07 sec) mysql> insert into demo50(start_date) values('2020−01−01'); Query OK, 1 row affected (0.14 sec)
Display records from the table using select statement −
mysql> select *from demo50;
This will produce the following output −
+----+---------------------+---------------------+ | id | start_date | end_date | +----+---------------------+---------------------+ | 1 | 2020−11−04 20:54:31 | 2020−11−04 20:54:31 | | 2 | 2020−11−04 20:54:53 | 2020−12−21 00:00:00 | | 3 | 2020−01−01 00:00:00 | 2020−11−04 20:55:04 | +----+---------------------+---------------------+ 3 rows in set (0.00 sec)
Advertisements