
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to update a timestamp field of a MySQL table?
- Creating a table with MySQL - Hibernate
- Creating a MySQL table using Node.js
- How to search for a date in MySQL timestamp field?
- Creating a MySQL Table in NodeJS using Sequelize
- Fix Error in MySQL syntax while creating a table column with name “index”?
- Can we use {} while creating a MySQL table?
- Set AUTO_INCREMENT in a table while creating it in MySQL?
- Selecting from a MySQL table based on parts of a timestamp?
- What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?
- Get two days data (today and yesterday) from a MySQL table with timestamp values
- Can we use current_date() for table with column timestamp default in MySQL?
- What is the MySQL syntax error in this query – Creating a table with reserved keyword?
- Creating a popup message box with an Entry field in tkinter
- Set DEFAULT values for columns while creating a table in MySQL

Advertisements