
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Insert Current Date in DATETIME Format in MySQL
To insert the current date (not time), then you can use in-built function CURDATE() from MySQL. The syntax is as follows −
INSERT INTO yourTableName values(curdate());
Or if you want to add date and time both then you can use the in-built function NOW() from MySQL. The syntax is as follows −
INSERT INTO yourTableName values(now());
To understand both the syntax, let us first create a table. The query to create a table is as follows −
mysql> create table NowAndCurdateDemo −> ( −> YourDueDate datetime −> ); Query OK, 0 rows affected (1.75 sec)
Implement both the functions to insert the current date and date-time the table. The query to insert date is as follows −
mysql> insert into NowAndCurdateDemo values(curdate()); Query OK, 1 row affected (0.28 sec) mysql> insert into NowAndCurdateDemo values(now()); Query OK, 1 row affected (0.14 sec)
Check whether the data is inserted or not in the table using the following query −
mysql> select *from NowAndCurdateDemo;
The following is the output −
+---------------------+ | YourDueDate | +---------------------+ | 2018-12-05 00:00:00 | | 2018-12-05 21:24:10 | +---------------------+ 2 rows in set (0.06 sec)
Advertisements