
- 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
How to add current date to an existing MySQL table?
To update an existing table, use UPDATE. With that, to set the current date, use the CURDATE() method −
update yourTableName set yourCoumnName=CURDATE();
Let us first create a table −
mysql> create table DemoTable -> ( -> DueDate datetime -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-10') ; Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('2019-03-31'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-01-10 00:00:00 | | 2019-03-31 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
Following is the query to add current date to existing table −
mysql> update DemoTable set DueDate=CURDATE(); Query OK, 2 rows affected (0.13 sec) Rows matched: 2 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-06-22 00:00:00 | | 2019-06-22 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to add columns to an existing MySQL table?
- How can we add columns with default values to an existing MySQL table?
- How to add column to an existing table in PostgreSQL?
- How can we add multiple columns, with single command, to an existing MySQL table?
- Add 11 days to current date in MySQL
- How to add columns at specific position in existing table in MySQL?
- How to write PHP script to update an existing MySQL table?
- How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?
- How to rename a column in an existing MySQL table?
- How to add a new column to an existing table using JDBC API?
- How to add +1 to existing MySQL values?
- Add some months to current date using Java with MySQL?
- Create MySQL query to create a table from an existing table?
- Adding new enum column to an existing MySQL table?
- How to generate a “create table” command based on an existing table in MySQL?

Advertisements