Tags
PHP , DATE
Asked 3 years ago
9 Jun 2021
Views 395
dilip

dilip posted

how to add three months to a date in php ?

how to add two or three or any number of the months to a date in php ?
pratik

pratik
answered Apr 26 '23 00:00

To add three months to a date in PHP, you can use the DateTime class and the modify () method to add 3 months to a given date.

Here's an example code:

php
Copy code
$date = new DateTime('2022-05-01');
$date->modify('+3 months');
echo $date->format('Y-m-d'); // outputs 2022-08-01
In this example, we first create a new DateTime object with the date we want to modify (2022-05-01 ). Then, we use the modify() method to add 3 months to the date. Finally, we format the date using the format () method to get the new date in the desired format (Y-m-d)
Post Answer