
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements