
- 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
How to create a table with date column?
To create a table with only date column, you can use DATE type. Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAdmissionDate DATE ); Query OK, 0 rows affected (0.47 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Chris',now()); Query OK, 1 row affected, 1 warning (0.12 sec) mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('Robert',curdate()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName,StudentAdmissionDate) values('David','2019-05-21'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+-----------+-------------+----------------------+ | StudentId | StudentName | StudentAdmissionDate | +-----------+-------------+----------------------+ | 1 | Chris | 2019-04-27 | | 2 | Robert | 2019-04-27 | | 3 | David | 2019-05-21 | +-----------+-------------+----------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to create a table with auto-increment column in MySQL using JDBC?
- How to change the date in a table with date records with MySQL?
- How to create a table with a caption?
- How to create a table with sub totals for every row and column in R?
- How to create a MySQL table with InnoDB engine table?
- How to create a MySQL table with MyISAM engine table?
- How can I create a MySQL table with a column with only 3 possible given values?
- How to create NA column for a contingency table in R?
- How to create a MySQL table with indexes?
- How to create a filter table with JavaScript?
- How to create a responsive table with CSS?
- How to create a comparison table with CSS?
- Create a date column in R using a date vector excluding weekends.
- How to compare the first date and the last date from a MySQL column with date records?
- How to create a date vector with randomization in R?

Advertisements