Tags
Asked 3 years ago
9 Jun 2021
Views 192
jagdish

jagdish posted

hoe to Add 20 years to date in php ?

how to 20 years to current date in php ?
yogi

yogi
answered Apr 26 '23 00:00

To add 20 years to a date in PHP, you can use the DateTime class and its


add

() method. Here's an example:

php
Copy code
$date = new DateTime('2022-05-01');
$date->add(new DateInterval('P20Y'));
echo $date->format('Y-m-d');
In this example, we create a new DateTime object for May 1st, 2022. We then use the add () method to add a DateInterval of 20 years ( P20Y) . Finally, we use the format () method to display the new date in the format YYYY-MM-DD. The output of this example will be 2042-05-01
Post Answer