- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add 1 day to the date in MySQL?
We can add 1 day to the date with the help of DATE_ADD() function.
Creating a table.
mysql> create table Add1DayDemo -> ( -> id int, -> MyDate datetime not null -> ); Query OK, 0 rows affected (1.06 sec)
Insert some records.
mysql> insert into Add1DayDemo values(1,now()); Query OK, 1 row affected (0.08 sec) mysql> insert into Add1DayDemo values(2,date_add(now(),interval 5 day)); Query OK, 1 row affected (0.16 sec)
To display all records.
mysql> select *from Add1DayDemo;
The following is the output.
+------+---------------------+ | id | MyDate | +------+---------------------+ | 1 | 2018-10-30 10:51:21 | | 2 | 2018-11-04 10:51:30 | +------+---------------------+ 2 rows in set (0.00 sec)
To add 1 day in field “MyDate”, use the SELECT
mysql> SELECT DATE_ADD(`MyDate`, INTERVAL 1 DAY) from Add1DayDemo -> where id=2;
The following is the output that shows the day, which was 4th November, increments by one, since we added a day.
+------------------------------------+ | DATE_ADD(`MyDate`, INTERVAL 1 DAY) | +------------------------------------+ | 2018-11-05 10:51:30 | +------------------------------------+ 1 row in set (0.00 sec)
Advertisements