
- 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
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 Articles
- MySQL - Insert current date/time?
- MySQL query to get current datetime and only current date
- Insert current date to the database in MySQL?
- How to insert current date/time 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?
- How to easily insert datetime in MySQL?
- How to Convert yyyymmddhhmmss Date Format to Normal Datetime in Excel?Datetime in Excel?
- 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
- Insert current time minus 1 hour to already inserted date-time records in MYSQL

Advertisements