How to Add Month to Date in PHP Tutorial

Share this Article
Reading Time: 3 minutes
228 Views

Inside this article we will see a basic concept of PHP i.e How to add month to date in PHP. Article contains classified information about adding month to a specific date or even with the current date in PHP.

We need this concept i.e adding days, adding month, remove days from a specific date is when we are creating some record type applications.

In PHP there are several functions which provide the function to add number of months into date. This concept will give you the understanding of adding 5 months, 7 months, 30 months etc into date.


Premium Courses Running Out, Grab Now!

Master the Coding Skills to Become an Expert in Web Development. A lifetime of knowledge at your fingertips.

Enroll in your favourite web development courses risk-free at $4 only.


Learn More –

Let’s get started.


Example 1: Add 5 months to a Specific date

Create a file index.php at your localhost directory.

Open index.php and write this complete code into it.

<?php
  
    $date = "2021-06-01";
    $newDate = date('Y-m-d', strtotime($date. ' + 5 months'));
  
    echo $newDate;
  
?>
  

Output

2021-11-01

Example 2: Add 5 months to current date

Create a file index.php at your localhost directory.

Open index.php and write this complete code into it.

<?php
  
    $newDate = date('Y-m-d', strtotime(' + 5 months'));
  
    echo $newDate;
  
?>
  

Output

2022-04-08

We hope this article helped you to learn How to Add Months to Date in PHP Tutorial in a very detailed way.

Buy Me a Coffee

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Read More Articles