![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Add two weeks to a date in MySQL?
To add two weeks to a date in MySQL, use DATE_ADD() −
insert into yourTableName(yourColumnName) values(date_add(now(),interval 2 week));
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.62 sec)
Following is the query to get the current date −
mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-02 10 :36 :49 | +-----------------------+ 1 row in set (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(ShippingDate) values(date_add(now(),interval 2 week)); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+-----------------------+ | Id | ShippingDate | +----+-----------------------+ | 1 | 2019-06-16 10 :37 :24 | +----+-----------------------+ 1 row in set (0.00 sec)
Advertisements