- 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 some days to str_to_date() MySQL function?
You can use DATE_ADD() function from MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> ShippingDate varchar(100) -> ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('06-01-2019'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('01-04-2017'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('29-06-2019'); Query OK, 1 row affected (0.47 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------------+ | ShippingDate | +--------------+ | 06-01-2019 | | 01-04-2017 | | 29-06-2019 | +--------------+ 3 rows in set (0.00 sec)
Following is the query to add some days to str_to_date() MySQL function. Here, we have added 6 days −
mysql> select date_add(str_to_date(ShippingDate,'%d-%m-%Y'),interval 6 day) as newShippingDate from DemoTable;
Output
+-----------------+ | newShippingDate | +-----------------+ | 2019-01-12 | | 2017-04-07 | | 2019-07-05 | +-----------------+ 3 rows in set (0.00 sec)
Advertisements