
- 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 a day to datetime field in MySQL query?
To add a day to datetime field, use the DATE_ADD() function. The syntax is as follows −
SELECT DATE_ADD(yourColumnName,interval yourIntegerValue day) as anyVariableName from yourTableName;
Let us first create a table −
mysql> create table AddOneDayDemo −> ( −> YourDay datetime −> ); Query OK, 0 rows affected (1.37 sec)
Insert current date with the help of curdate() and after that use date_add() function to add a day.
To insert a day into the table, the following is the query −
mysql> insert into AddOneDayDemo values(curdate()); Query OK, 1 row affected (0.17 sec)
Display records with the help of select statement. The query is as follows −
mysql> select *from AddOneDayDemo;
The following is the record with current date −
| YourDay | +---------------------+ | 2018-11-27 00:00:00 | +---------------------+ 1 row in set (0.00 sec)
The query to add a day to current date is as follows −
mysql> select date_add(YourDay,interval 1 day) as yourDayafteraddingoneday from AddOneDayDemo;
The following is the output -
+--------------------------+ | yourDayafteraddingoneday | +--------------------------+ | 2018-11-28 00:00:00 | +--------------------------+ 1 row in set (0.00 sec)
The above output displays a date that is an addition to the current date.
- Related Articles
- How can I add one day to DATETIME field in MySQL query?
- Add a single day to datetime field with MySQL INTERVAL
- How to convert char field to datetime field in MySQL?
- Add DATE and TIME fields to get DATETIME field in MySQL?
- MongoDB query to convert the field value and create datetime day of month during projection?
- How to add 30 minutes to datetime in MySQL?
- Adding a day to a DATETIME format value in MySQL?
- MySQL Datetime to add days?
- How to add a day to the date in MySQL?
- How to update date of datetime field with MySQL?
- MySQL query to set current date in the datetime field for all the column values
- Insert datetime into another datetime field in MySQL?
- MySQL Query to convert from datetime to date?
- How to add time in a MySQL column set with type DATETIME?
- How to add 1 day to the date in MySQL?

Advertisements