

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a temporary table with dates in MySQL
To create a temporary table with dates, use the CREATE TEMPORARY TABLE in MySQL. Following is the syntax −
Syntax
create temporary table yourTableName( yourColumnName datetime );
Let us first create a table −
mysql> create temporary table DemoTable -> ( -> DueDate datetime -> ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(now()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable values(curdate()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable values('2018-01-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable values('2019-12-31'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-10-27 18:07:41 | | 2019-10-27 00:00:00 | | 2018-01-21 00:00:00 | | 2019-12-31 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Create a temporary table in a MySQL procedure?
- Create a temporary table similar to a regular table with MySQL LIKE
- How to create a temporary MySQL table in a SELECT statement without a separate CREATE TABLE?
- How can we create a MySQL temporary table by using PHP script?
- Insert multiple values in a temporary table with a single MySQL query?
- How can I delete MySQL temporary table?
- How to list temporary table columns in MySQL?
- Filter dates from a table with DATE and NULL records in MySQL
- Add a temporary column with a value in MySQL?
- Update table and order dates in MySQL
- How to create a MySQL table with InnoDB engine table?
- How to create a MySQL table with MyISAM engine table?
- Create a temporary file in Java
- How to change format of dates in a table column with a MySQL query?
- How to create a vector with dates between two dates in R?
Advertisements