
- 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
Insert current date in datetime format 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)
- Related Questions & Answers
- MySQL - Insert current date/time?
- MySQL query to get current datetime and only current date
- How to insert current date/time in MySQL?
- Insert current date to the database in MySQL?
- Change the curdate() (current date) format in MySQL
- How to convert US date format to MySQL format in INSERT query?
- Insert datetime into another datetime field in MySQL?
- MySQL query to insert current date plus specific time?
- Add10 minutes to MySQL datetime format?
- How to easily insert datetime in MySQL?
- C# DateTime to add days to the current date
- How can we insert current date automatically in a column of MySQL table?
- How to insert current date/ time using now() in a field with MySQL?
- How do I re-format datetime in MySQL?
- MySQL query to set current date in the datetime field for all the column values
Advertisements