Add Days, Weeks, Months, Year to the Existing date in PHP

php-date-functionPHP is a very popular and pretty easy technology comparing other programming languages. Date function is a very important function in any technology and in PHP it is quite easily understandable and In this post we are going to learn how to add days, weeks, months, year in PHP.

Adding dates is very in PHP and it is like writing human readable strings only, once you come to know this you don’t need to memorize at all.

Lets begin:

Existing Date: 2013-09-11

1. Adding day(s) to a date:

Output will be:
2013-09-12

 

2. Adding Week(s) to a date:

Output will be:
2013-09-25

 

3. Adding Month(s) to a date:

Output will be:
2013-10-11

 

4. Adding Year(s) to a date:

Output will be:
2016-09-11

 

I hope this is clear enough to understand how you can add dates or weeks or years to any date from the above examples.

Related Posts

7 thoughts on “Add Days, Weeks, Months, Year to the Existing date in PHP

  1. when we are giving before date as 30/jan/2019,
    and coded to add one month.then its gave result as 02/march/2019.
    what am i do now.

  2. This is failed when you want to add 6 months and next year is leap year. For an example:
    if you give date 31-Aug-2019 the added 6 months then it will give you date 01-Mar-2020. which is wrong. It should be 29-Feb-2020

Leave a Reply