
- 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
MySQL - Insert current date/time?
To insert only date value, use curdate() in MySQL. With that, if you want to get the entire datetime, then you can use now() method.
Let us first create a table −
mysql> create table CurDateDemo -> ( -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.74 sec)
Now you can insert only date with the help of curdate() method −
mysql> insert into CurDateDemo values(curdate()); Query OK, 1 row affected (0.15 sec)
Display the inserted date with the help of select statement. The query is as follows −
mysql> select *from CurDateDemo;
Here is the output −
+---------------------+ | ArrivalDate | +---------------------+ | 2018-11-23 00:00:00 | +---------------------+ 1 row in set (0.00 sec)
Let us now create a table and display the current datetime −
mysql> create table NowDemo -> ( -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.47 sec)
Insert both date and time with the help of now().
The query to insert record is as follows −
mysql> insert into NowDemo values(now()); Query OK, 1 row affected (0.16 sec)
Let us now check whether the date and time is inserted or not. The query to display records is as follows −
mysql> select *from NowDemo;
The following is the output −
+---------------------+ | ArrivalDate | +---------------------+ | 2018-11-23 17:31:26 | +---------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to insert current date/time in MySQL?
- MySQL query to insert current date plus specific time?
- Insert current time minus 1 hour to already inserted date-time records in MYSQL
- Insert current date in datetime format MySQL?
- How to insert current date/ time using now() in a field with MySQL?
- Insert current date to the database in MySQL?
- How to insert current date and time in a database using JDBC?
- How can we insert current date and time automatically on inserting values in other columns in MySQL?
- Set current date and time to timestamp in MySQL
- How can we insert current date automatically in a column of MySQL table?
- Current Date and Time in Perl
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- Java Program to Get Current Date/Time
- Get current date/time in seconds - JavaScript?
- Get current time and date on Android

Advertisements