
- 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 query to set current date in the datetime field for all the column values
Let us first create a table −
mysql> create table DemoTable821(AdmissionDate datetime); Query OK, 0 rows affected (1.24 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable821 values('2019-01-21'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable821 values('2018-11-02'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable821 values('2016-12-31'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable821 values('2015-03-19'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable821;
This will produce the following output −
+---------------------+ | AdmissionDate | +---------------------+ | 2019-01-21 00:00:00 | | 2018-11-02 00:00:00 | | 2016-12-31 00:00:00 | | 2015-03-19 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
Here is the query to set current date in the DateTime field −
mysql> update DemoTable821 set AdmissionDate=CURDATE(); Query OK, 4 rows affected (0.74 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check table records once again −
mysql> select *from DemoTable821;
This will produce the following output −
+---------------------+ | AdmissionDate | +---------------------+ | 2019-08-03 00:00:00 | | 2019-08-03 00:00:00 | | 2019-08-03 00:00:00 | | 2019-08-03 00:00:00 | +---------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to get current datetime and only current date
- How to set all values in a single column MySQL Query?
- Set a MySQL field with the current date (UNIX_TIMESTAMP(now))
- MySQL query to get the character length for all the values in a column?
- How to update column values with date records and set 1 for corresponding records before the current date in SQL
- Insert current date in datetime format MySQL?
- Set all values in a MySQL field to 0?
- MySQL Query to convert from datetime to date?
- Set 'alias' for all the column names in a single MySQL query
- How to get the possible values for SET field in MySQL?
- How to update date of datetime field with MySQL?
- MySQL query to get the current date records wherein one of the columns displays current date
- MySQL query to set values for NULL occurrence
- Set ENUM in MySQL for column values
- MySQL query to select date >= current date - 3 weeks?

Advertisements