
- 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
Update MySQL table column by matching date using date() function?
Following is the syntax to match date with date() function and updating a column −
update yourTableName set yourColumnName=yourValue where date(yourColumnName)=curdate();
Let us first create a table −
mysql> create table DemoTable1816 ( Name varchar(20), JoiningDate datetime ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1816 values('Chris','2019-11-29 12:34:50'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1816 values('David','2019-11-30 11:00:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1816 values('Mike','2018-11-30 10:20:30'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1816;
This will produce the following output −
+-------+---------------------+ | Name | JoiningDate | +-------+---------------------+ | Chris | 2019-11-29 12:34:50 | | David | 2019-11-30 11:00:00 | | Mike | 2018-11-30 10:20:30 | +-------+---------------------+ 3 rows in set (0.00 sec)
Here is the query to update a column by matching date −
mysql> update DemoTable1816 set Name='Robert' where date(JoiningDate)=curdate(); Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1816;
This will produce the following output −
+--------+---------------------+ | Name | JoiningDate | +--------+---------------------+ | Chris | 2019-11-29 12:34:50 | | Robert | 2019-11-30 11:00:00 | | Mike | 2018-11-30 10:20:30 | +--------+---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Update record on a specific date matching the current date in MySQL
- How to update a MySQL date type column?
- Update MySQL date and increment by one Year?
- MySQL date column auto fill with current date?
- Perform MySQL UPDATE on the basis of DATE value in another column
- Validate Date in MySQL using a custom function
- MySQL GROUP BY date when using datetime?
- Display matching repeated date records only once in MySQL
- MySQL DATE function to return the difference between current date and joining date
- MySQL query to update only month in date?
- How to update the date format in MySQL?
- How to search a record by date in MySQL table?
- MySQL ORDER BY Date field not in date format?
- How to update a MySQL table by swapping two column values?
- How to create a table with date column?

Advertisements