
- 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
Adding a day to a DATETIME format value in MySQL?
To add a day to a DATETIME format value, you can use DATE_ADD() function from MySQL.
The syntax is as follows −
select date_add(now(),interval 1 day) as anyVariableName;
Now you can implement the above syntax in order to add a day to a datetime format.
mysql> select date_add(now(),interval 1 day) as Adding1DayDemo;
The following is the output −
+---------------------+ | Adding1DayDemo | +---------------------+ | 2018-12-07 20:06:59 | +---------------------+ 1 row in set (0.00 sec)
If you want to add a day only to a date, you can use curdate() function. The query is as follows −
mysql> select date_add(curdate(),interval 1 day) as Adding1DayDemo;
The following is the output −
+----------------+ | Adding1DayDemo | +----------------+ | 2018-12-07 | +----------------+ 1 row in set (0.00 sec)
Let us create a table and insert some date values to it −
mysql> create table AddOneday −> ( −> DueTime datetime −> ); Query OK, 0 rows affected (1.05 sec)
Now you can insert records with the help of both the functions now() and curdate().The query is as follows −
mysql> insert into AddOneday values(now()); Query OK, 1 row affected (0.22 sec) mysql> insert into AddOneday values(curdate()); Query OK, 1 row affected (0.53 sec)
Display all records from the table with the help of select statement −
mysql> select *from AddOneday;
The following is the output −
+---------------------+ | DueTime | +---------------------+ | 2018-12-06 20:10:47 | | 2018-12-06 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
Add a day with the help of DATE_ADD(). The query is as follows −
mysql> select date_add(DueTime,interval 1 day) as AddingOneDay from AddOneday;
The following is the output displaying the updated dates −
+---------------------+ | AddingOneDay | +---------------------+ | 2018-12-07 20:10:47 | | 2018-12-07 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- How to add a day to datetime field in MySQL query?
- How to use MySQL FROM_UNIXTIME() function to return datetime value in numeric format?
- Add a single day to datetime field with MySQL INTERVAL
- Insert current date in datetime format MySQL?
- Add10 minutes to MySQL datetime format?\n\n
- What is the correct DateTime format for a MySQL Database?
- How to Convert Text Datetime Format to Real Datetime Format in Excel?
- How do I re-format datetime in MySQL?
- Input type DateTime Value format with HTML
- How to convert string to 24-hour datetime format in MySQL?
- How to check if a datetime value equals tomorrows date in MySQL?
- How can I add one day to DATETIME field in MySQL query?
- How to fix the incorrect datetime value while inserting in a MySQL table?
- Format MySQL date and convert to year-month-day

Advertisements