- 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
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)
Advertisements